Android中的JSON数组解析 [英] JSON array parsing in android

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

问题描述

这是我的JSON对象,我想在android项目中解析它

Here is my JSON object and i want to parse it in android project

{
    "second": {
        "versionInfo": "0.20.3-dev",
        "compileDate": "Mon Mar 12 17:39:23 IST 2012",
        "compileUser": "suraj",
        "trackname": "tracker_localhost:localhost/127.0.0.1:48418"
    },
    "href": {
        "versionInfo": "null",
        "compileDate": "null",
        "compileUser": "null",
        "trackname": "null"
    },
    "first": {
        "key": "['trackname','versionInfo','compileDate','compileUser']"
    }
}

如何编译? 我想先提取第一"的属性并使用该属性,然后再使用第一"的属性提取第二"的参数.

How to compile? i want to first extract attributes of 'first' and using the attributes and then to extract parameters of 'second' using attributes of 'first'.

推荐答案

基本上是这样完成的:

JSONObject jobj = new JSONObject(theString);
JSONObject first = jobj.getJSONObject("first");
JSONObject second = jobj.getJSONObject("second");

如果需要更多内容,请查看 JSON类的文档对于Android .

If you want more, take a look at the documentation of JSON classes for android.

修改

关于数组的提取(在first-> key中):

Regarding the extraction of the array (in first->key):

String jStr = first.getString("key");
JSONArray jArr = new JSONArray(jStr);

这篇关于Android中的JSON数组解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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