Java 使用org.JSON解析JSON文件

Java 使用org.JSON解析JSON文件,java,android,Java,Android,如何解析这样的JSON [{ "id" : 28010942, "type" : "trafficlight", "title" : "225 - Shaw Blvd. / Gomezville - Flashing", "activeFrom" : "Apr 30, 2013 6:18:00 PM", "publiclyVisible" : true, "locationLat" : 14.589366803498653, "locati

如何解析这样的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" : ""
} ...
]

我可以解析那些有对象和JSONArray的,但是这个没有。我如何迭代这些,并能够像“id”一样存储每个信息。我正在使用org.json库,还是应该使用其他库?

如果需要解析,请尝试下面的方法

[           // 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..
   }
JSONArray jarray=newjsonarray(“Myjsonstring”);

对于(int i=0;i)你说它没有是什么意思?
[
表示json数组节点,
{
表示json对象node@Raghunandan,但为了能够解析它,我需要一个名称,对吗?像这样
jsonFile.getJSONObject(“字符串”)或jsonFile.getJSONArray(“字符串”)
既然它是空的,我应该如何访问它们?如何获取json?它是字符串吗?@Raghunandan,是的,它是字符串。谢谢!我没有想到要立即使用字符串创建jsonArray。非常感谢!