用Java阅读JSON文件的问题

时间:2015-09-23 09:21:07

标签: java json jackson

我正在尝试使用map(ObjectMapper and TypeReference)在java中读取此文件,但map只选择一个数据,即name: "David Roberts"slug: "david-robets"assigned: "assigned"

我也尝试使用JsonParser,但没有得到合适的结果。

对此有任何建议:

{
  "name": "David Roberts",
  "slug": "david-roberts",
  "assigned": "assigned"
},
{
  "name": "Robert Chang",
  "slug": "robert-chang",
  "assigned": "assigned"
},
{
  "name": "Chris Curtis",
  "slug": "chris.curtis",
  "assigned": "assigned",
  "fileId": "1370206"
}

2 个答案:

答案 0 :(得分:0)

您的json文件错误。 正确的格式是:

[{
  "name": "David Roberts",
  "slug": "david-roberts",
  "assigned": "assigned"
},
{
  "name": "Robert Chang",
  "slug": "robert-chang",
  "assigned": "assigned"
},
{
  "name": "Chris Curtis",
  "slug": "chris.curtis",
  "assigned": "assigned",
  "fileId": "1370206"
}]

答案 1 :(得分:0)

如果你想要所有的值,那么json应该是这样的。

{"values":[{
          "name": "David Roberts",
          "slug": "david-roberts",
          "assigned": "assigned"
        },
        {
          "name": "Robert Chang",
          "slug": "robert-chang",
          "assigned": "assigned"
        },
        {
          "name": "Chris Curtis",
          "slug": "chris.curtis",
          "assigned": "assigned",
          "fileId": "1370206"
        }]

    }