Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android-JSON列表<;对象>;铸造问题“;预期开始“U数组”;_Java_Android_Gson - Fatal编程技术网

Java Android-JSON列表<;对象>;铸造问题“;预期开始“U数组”;

Java Android-JSON列表<;对象>;铸造问题“;预期开始“U数组”;,java,android,gson,Java,Android,Gson,我是android和java开发的新手。 我试图让乔森在安卓系统中上市,但我面临这个问题。 你能帮我解决这个问题吗 错误:java.lang.IllegalStateException:应为BEGIN\u数组,但为 从第1行第2列路径开始\u对象$ 转换代码 Gson gson = new Gson(); String jsonOutput = githubSearchResults; Type listType = new TypeToken<List<GitRepo>>

我是android和java开发的新手。 我试图让乔森在安卓系统中上市,但我面临这个问题。 你能帮我解决这个问题吗

错误:java.lang.IllegalStateException:应为BEGIN\u数组,但为 从第1行第2列路径开始\u对象$

转换代码

Gson gson = new Gson();
String jsonOutput = githubSearchResults;
Type listType = new TypeToken<List<GitRepo>>(){}.getType();
List<GitRepo> oData = gson.fromJson(jsonOutput, listType);

您得到的响应是一个
JSONObject
,它是一个单一实体(
GitRepo
对象),而不是
集合

您需要将变量的类型从
List
更改为单个对象,该对象是
GitRepo
的实例,如下所示-

GitRepo oData = gson.fromJson(jsonOutput, GitRepo.class);

JSON请求URL:
第1行第2列
。。。这是一个
{
字符(对象),但您试图将其解析为,
[
字符(列表),您的类需要以大写开头。请遵循Java命名约定。相同错误:Java.lang.IllegalStateException:应为BEGIN_数组,但在第1行第162列路径$.items[0]处为BEGIN_对象。ownerGson gson=new gson();String jsonOutput=githubSearchResults;GitRepo oData=gson.fromJson(jsonOutput,GitRepo.class);我已根据您的建议更改了代码,但错误仍然相同。问题已解决。谢谢
{
  "total_count": 68,
  "incomplete_results": false,
  "items": [
    {
      "id": 1604375,
      "node_id": "MDEwOlJlcG9zaXRvcnkxNjA0Mzc1",
      "name": "w2ui",
      "full_name": "vitmalina/w2ui",
      "owner": {
        "login": "vitmalina",
        "id": 561995,
        "node_id": "MDQ6VXNlcjU2MTk5NQ==",
        "avatar_url": "https://avatars0.githubusercontent.com/u/561995?v=4",
        "gravatar_id": "",
        "url": "https://api.github.com/users/vitmalina",
        "html_url": "https://github.com/vitmalina",
        "followers_url": "https://api.github.com/users/vitmalina/followers",
        "following_url": "https://api.github.com/users/vitmalina/following{/other_user}",
        "gists_url": "https://api.github.com/users/vitmalina/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/vitmalina/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/vitmalina/subscriptions",
        "organizations_url": "https://api.github.com/users/vitmalina/orgs",
        "repos_url": "https://api.github.com/users/vitmalina/repos",
        "events_url": "https://api.github.com/users/vitmalina/events{/privacy}",
        "received_events_url": "https://api.github.com/users/vitmalina/received_events",
        "type": "User",
        "site_admin": false
      },
      "private": false,
      "html_url": "https://github.com/vitmalina/w2ui",
      "description": "JavaScript UI library for data-driven web applications",
      "fork": false,
      "url": "https://api.github.com/repos/vitmalina/w2ui",
      "forks_url": "https://api.github.com/repos/vitmalina/w2ui/forks",
      "keys_url": "https://api.github.com/repos/vitmalina/w2ui/keys{/key_id}",
      "collaborators_url": "https://api.github.com/repos/vitmalina/w2ui/collaborators{/collaborator}",
      "teams_url": "https://api.github.com/repos/vitmalina/w2ui/teams",
      "hooks_url": "https://api.github.com/repos/vitmalina/w2ui/hooks",
      "issue_events_url": "https://api.github.com/repos/vitmalina/w2ui/issues/events{/number}",
      "events_url": "https://api.github.com/repos/vitmalina/w2ui/events",
      "assignees_url": "https://api.github.com/repos/vitmalina/w2ui/assignees{/user}",
      "branches_url": "https://api.github.com/repos/vitmalina/w2ui/branches{/branch}",
      "tags_url": "https://api.github.com/repos/vitmalina/w2ui/tags",
      "blobs_url": "https://api.github.com/repos/vitmalina/w2ui/git/blobs{/sha}",
      "git_tags_url": "https://api.github.com/repos/vitmalina/w2ui/git/tags{/sha}",
      "git_refs_url": "https://api.github.com/repos/vitmalina/w2ui/git/refs{/sha}",
      "trees_url": "https://api.github.com/repos/vitmalina/w2ui/git/trees{/sha}",
      "statuses_url": "https://api.github.com/repos/vitmalina/w2ui/statuses/{sha}",
      "languages_url": "https://api.github.com/repos/vitmalina/w2ui/languages",
      "stargazers_url": "https://api.github.com/repos/vitmalina/w2ui/stargazers",
      "contributors_url": "https://api.github.com/repos/vitmalina/w2ui/contributors",
      "subscribers_url": "https://api.github.com/repos/vitmalina/w2ui/subscribers",
      "subscription_url": "https://api.github.com/repos/vitmalina/w2ui/subscription",
      "commits_url": "https://api.github.com/repos/vitmalina/w2ui/commits{/sha}",
      "git_commits_url": "https://api.github.com/repos/vitmalina/w2ui/git/commits{/sha}",
      "comments_url": "https://api.github.com/repos/vitmalina/w2ui/comments{/number}",
      "issue_comment_url": "https://api.github.com/repos/vitmalina/w2ui/issues/comments{/number}",
      "contents_url": "https://api.github.com/repos/vitmalina/w2ui/contents/{+path}",
      "compare_url": "https://api.github.com/repos/vitmalina/w2ui/compare/{base}...{head}",
      "merges_url": "https://api.github.com/repos/vitmalina/w2ui/merges",
      "archive_url": "https://api.github.com/repos/vitmalina/w2ui/{archive_format}{/ref}",
      "downloads_url": "https://api.github.com/repos/vitmalina/w2ui/downloads",
      "issues_url": "https://api.github.com/repos/vitmalina/w2ui/issues{/number}",
      "pulls_url": "https://api.github.com/repos/vitmalina/w2ui/pulls{/number}",
      "milestones_url": "https://api.github.com/repos/vitmalina/w2ui/milestones{/number}",
      "notifications_url": "https://api.github.com/repos/vitmalina/w2ui/notifications{?since,all,participating}",
      "labels_url": "https://api.github.com/repos/vitmalina/w2ui/labels{/name}",
      "releases_url": "https://api.github.com/repos/vitmalina/w2ui/releases{/id}",
      "deployments_url": "https://api.github.com/repos/vitmalina/w2ui/deployments",
      "created_at": "2011-04-12T14:26:20Z",
      "updated_at": "2018-07-02T20:33:42Z",
      "pushed_at": "2018-06-11T02:02:49Z",
      "git_url": "git://github.com/vitmalina/w2ui.git",
      "ssh_url": "git@github.com:vitmalina/w2ui.git",
      "clone_url": "https://github.com/vitmalina/w2ui.git",
      "svn_url": "https://github.com/vitmalina/w2ui",
      "homepage": "http://w2ui.com",
      "size": 38068,
      "stargazers_count": 1612,
      "watchers_count": 1612,
      "language": "JavaScript",
      "has_issues": true,
      "has_projects": true,
      "has_downloads": true,
      "has_wiki": true,
      "has_pages": false,
      "forks_count": 562,
      "mirror_url": null,
      "archived": false,
      "open_issues_count": 309,
      "license": {
        "key": "mit",
        "name": "MIT License",
        "spdx_id": "MIT",
        "url": "https://api.github.com/licenses/mit",
        "node_id": "MDc6TGljZW5zZTEz"
      },
      "forks": 562,
      "open_issues": 309,
      "watchers": 1612,
      "default_branch": "master",
      "score": 150.9138
    }
  ]
}
GitRepo oData = gson.fromJson(jsonOutput, GitRepo.class);