-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 に答える