0

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'.

4

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

3 Comments

thanks....but how to get values from key 'key' in 'first' object....as there is only one key and value is array of attributes?
one at a time :). The value of "key" is NOT an array but a String (that contains a serialized JSON array). I will edit in a few minutes, but if you read the documentation it'll be easier for you in the future.
thank you very much....actually i am new to json and android thats why i dont know the exact concept.........anyway i will keep in mind your suggestion..and again thanks for help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.