如何在android中解析没有json对象标题的json数组?

mal*_*ika 2 android json http

   [
    {
        "name":           "The Universe & The Earth"
      , "imagename":      "cat1.jpg"
      , "active":         "Y"
      , "createdon":      "1901-01-01"
      , "lastmodifiedon": "1901-01-01 00:00:00"
      , "description":    "Knowledge of Earth location in the universe has been shaped by 400 years of telescopic observations, and has expanded radically in the last century.\n"
      , "id":             "1"
    }
  , {
        "name":           "Life on Earth"
      , "imagename":      "cat2.jpg"
      , "active":         "Y"
      , "createdon":      "1901-01-01"
      , "lastmodifiedon": "1901-01-01 00:00:00"
      , "description":    "Over the last 3.7 billion years or so, living organisms on the Earth have diversified and adapted to almost every environment imaginable."
      , "id":             "2"
    }
]
Run Code Online (Sandbox Code Playgroud)

这是我的json值.现在我想解析并显示在自定义列表视图中我该怎么做?我跟着http://www.androidhive.info/2012/01/android-json-parsing-tutorial/这是链接但无法实现.我怎样才能做到这一点?有人能告诉我吗?提前致谢.

Ben*_*alb 8

这是一个JSONArray而不是JSONObject - 从中​​创建一个JSONObject,使用

JSONObject jsonObject = jsonArray.getJSONObject(0);
Run Code Online (Sandbox Code Playgroud)

这从这个JSONArray获取第一个JSONObject.

如果您有多个JSONObjects,请使用:

JSONObject jsonObject;
for(int n = 0; n < jsonArray.length(); n++)
{
    jsonObject = jsonArray.getJSONObject(n);
}
Run Code Online (Sandbox Code Playgroud)

获取值:

jsonObject.getString("name");
Run Code Online (Sandbox Code Playgroud)