如何用java中的另一个json解析JSON?

时间:2015-11-18 13:00:35

标签: java json jackson

这是我的JSON:

{
  "results": [
    {
      "username": "bigglesworth",
      "phone": "650-253-0000",
      "createdAt": "2011-11-07T20:58:06.445Z",
      "updatedAt": "2011-11-07T20:58:06.445Z",
      "objectId": "3KmCvT7Zsb"
    },
    {
      "username": "cooldude6",
      "phone": "415-369-6201",
      "createdAt": "2011-11-07T20:58:34.448Z",
      "updatedAt": "2011-11-07T21:25:10.623Z",
      "objectId": "g7y9tkhB7O"
    }
  ]
}

我如何解析这个json? 当我尝试使用jason解析此问题时,我重新尝试了此错误消息

  

"线程中的异常" main"

     

com.fasterxml.jackson.databind.JsonMappingException:不能   从START_OBJECT反序列化java.util.ArrayList的实例   令牌"

1 个答案:

答案 0 :(得分:0)

如果没有第三方库,您可以执行类似

的操作
JSONObject jsonObject = new JSONObject(jsonAsString);
JSONArray results = jsonObject.getJSONArray("results");
for(int i=0; i<results.length(); i++) {
    JSONObject result = results.getJSONObject(i);
    String username = result.getString("username");
    //...
}
相关问题