user6456773 user6456773 - 1 year ago 117
JSON Question

Java: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $

SOLVED! Check the answers below

I am working with the GitHub repo, want to access the names of the users' repos. The JSON looks like this:

"id": 55848012,
"name": "Android",
"full_name": "VyaraGGeorgieva/Android"

I have a Repo class

public class Repo {

private String name;

public String getName() {
return name;

public void setName(String name) { = name;


And a class, storing the returned query:

public class GitHubRepos {

private Repo[] repos;

public Repo[] getRepos() {
return repos;

public void setRepos(Repo[] repos) {
this.repos = repos;

The endPoint is defines as this:

Call<List<GitHubRepos>> getRepoName(@Path("user") String name);

When I try to execute the calling:

call.enqueue(new Callback<List<GitHubRepos>>() {
public void onResponse(Call<List<GitHubRepos>> call, Response<List<GitHubRepos>> response) {
Repo[] repos = response.body().**getRepos()**;
Log.d("Repos: ", "Number of repos received: " + repos.length);

Defined on this way, I can't access the getRepos() method.

I don't define correctly some types, but not sure how to fix the problem.

Answer Source

you need to pass List instead of Object.

call.enqueue(new Callback<List<GitHubRepos>>() {
        //override method.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download