简体   繁体   中英

JSON array parsing in 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'.

Basically it is done like that:

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

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

Edit

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM