如何解析而不android的JSON对象标题JSON数组? [英] How to parse json array without json object title in android?

查看:151
本文介绍了如何解析而不android的JSON对象标题JSON数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

   [
    {
        "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"
    }
]

这是我的JSON值。现在,我想分析和自定义列表视图中显示我怎么能
     做这个?我跟着 http://www.androidhive.info/2012/01/ Android的JSON的解析教程/ 这是链接,但无法实现。我怎样才能做到这一点?谁能告诉我?先谢谢了。

This is my json values. Now i want to parse and displayed in custom list view how can i do this? I followed http://www.androidhive.info/2012/01/android-json-parsing-tutorial/ this is link but can't be achieve. How can i do this? Can anybody tell me? Thanks in advance.

推荐答案

这是一个JSONArray,而不是一个JSONObject - 从中​​做出一个JSONObject,用

This is a JSONArray and not a JSONObject - to make a JSONObject from it, use

JSONObject jsonObject = jsonArray.getJSONObject(0);

这从这个JSONArray得到第一个JSONObject的。

this gets the first JSONObject from this JSONArray.

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

If you have multiple JSONObjects, use this:

JSONObject jsonObject;
for(int n = 0; n < jsonArray.length(); n++)
{
    jsonObject = jsonArray.getJSONObject(n);
}

要获取值:

jsonObject.getString("name");

这篇关于如何解析而不android的JSON对象标题JSON数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆