-1

我如何解析这样的 JSON?

[{
    "id" : 28010942,
    "type" : "trafficlight",
    "title" : "225 - Shaw Blvd. / Gomezville - Flashing",
    "activeFrom" : "Apr 30, 2013 6:18:00 PM",
    "publiclyVisible" : true,
    "locationLat" : 14.589366803498653,
    "locationLon" : 121.03713870048522,
    "publicDescription" : ""
}, {
    "id" : 28010939,
    "type" : "trafficlight",
    "title" : "301 - Andalucia (A. Mendoza) / P. Campa - No Display",
    "activeFrom" : "Apr 30, 2013 6:00:00 PM",
    "publiclyVisible" : true,
    "locationLat" : 14.608034456366056,
    "locationLon" : 120.98599433898926,
    "publicDescription" : ""
} ...
]

我可以解析具有对象和 jsonArrays 的对象,但这个对象都没有。我如何遍历这些并能够存储每个信息,如“id”。我正在使用 org.json 库,还是应该使用其他库?

4

1 回答 1

1

如果您需要解析,请尝试以下

[           // json array node
    {       // json object node
        "id": 28010942,      
        "type": "trafficlight",

解析

   JSONArray jarray = new JSONArray("Myjsonstring");
   for(int i=0 ;i<jarray.length();i++)
   {
   JSONObject jb = (JSONObject)jarray.get(i); 
   String id = jb.getString("id");
   String type = jb.getString("type");
   // same for others title, activeform..
   }
于 2013-08-30T16:04:31.573 回答