Android 如何使用json解析获取值。?

Android 如何使用json解析获取值。?,android,json,Android,Json,我在安卓系统工作。我想显示用户的签入列表 我得到的结果是json格式的。现在我想对它进行解析 以下是我的输出:- { "meta": { "code":200, "errorType":"deprecated", "errorDetail":"" }, "notifications": [ { "type":"notificationTray",

我在安卓系统工作。我想显示用户的签入列表

我得到的结果是json格式的。现在我想对它进行解析

以下是我的输出:-

{
   "meta":         
   {
        "code":200,     
        "errorType":"deprecated",     
        "errorDetail":""
   },

   "notifications": [
      {
         "type":"notificationTray",    
         "item":{
                   "unreadCount":0   
         }
      }
   ],
   "response":{

      "groups":[    
         {
            "type":"nearby",
            "name":"Nearby",
            "items":[
               {
                  "id":"4ed0c8f48231b9ef88fe5f09",
                  "name":"Banayan Tree School",
                  "contact":{

                  },
                  "location":{
                     "lat":26.857954980225713,
                     "lng":75.76602927296061,
                     "distance":510
                  },
                  "categories":[
                     {
                        "id":"4bf58dd8d48988d1a8941735",
                        "name":"General College & University",
                        "pluralName":"General Colleges & Universities",
                        "shortName":"Other - Education",
                        "icon":"https:\/\/foursquare.com\/img\/categories\/education\/default.png",
                        "parents":[
                           "Colleges & Universities"
                        ],
                        "primary":true
                     }
                  ],
                  "verified":false,
                  "stats":{
                     "checkinsCount":5,
                     "usersCount":4,
                     "tipCount":0
                  },
                  "hereNow":{
                     "count":0
                  }
               },
               {
                  "id":"4e75f61fae60c32851596918",
                  "name":"Rajat Path",
                  "contact":{

                  },
                  "location":{
                     "lat":26.866031,
                     "lng":75.759431,
                     "distance":701,
                     "city":"Jaipur",
                     "state":"Rajasthan"
                  },
                  "categories":[
                     {
                        "id":"4d4b7105d754a06378d81259",
                        "name":"Shop & Service",
                        "pluralName":"Shops & Services",
                        "shortName":"Shops",
                        "icon":"https:\/\/foursquare.com\/img\/categories\/shops\/default.png",
                        "parents":[

                        ],
                        "primary":true
                     }
                  ],
                  "verified":false,
                  "stats":{
                     "checkinsCount":3,
                     "usersCount":3,
                     "tipCount":0
                  },
                  "hereNow":{
                     "count":0
                  }
     }
            ]
         }
      ]
   }
}
请告诉我如何在我的数组中获取checkinscount

提前感谢您。

这里有一种使用的方法,这就是imho最好的JSON库:

final ObjectMapper mapper = new ObjectMapper();

final JsonNode input = mapper.readTree(...); // fill as appropriate

final JsonNode items = input.path("response").path("groups").path("items");

if (!items.isArray())
     // bad input

int total = 0;
JsonNode checkinscount;

// Cycle through array elements -- this works since JsonNode implements Iterable<JsonNode>
for (final JsonNode element: items) {
    checkinscount = element.path("stats").path("checkinscount");
    if (!checkinscount.isInt())
        // bad input
    total += checkinscount.getIntValue();
}
final ObjectMapper mapper=new ObjectMapper();
最终JsonNode输入=mapper.readTree(…);//斟酌填写
final JsonNode items=input.path(“response”).path(“groups”).path(“items”);
如果(!items.isArray())
//输入错误
int-total=0;
JsonNode-checkinscount;
//循环遍历数组元素——这是因为JsonNode实现了Iterable
for(最终JsonNode元素:items){
checkinscount=element.path(“stats”).path(“checkinscount”);
如果(!checkinscount.isInt())
//输入错误
total+=checkinscount.getIntValue();
}

Dude,格式化你的帖子。没有人会读这个。考虑使用。谢谢你,Jens…非常感谢你。。。谢谢你,Flo…使用Gson解析。这是您添加到Android项目中的一个小库,但非常容易使用,并且可以完成这项工作。我已经在安卓系统中使用了它,我非常满意。