0

I've been trying to parse the following in my android application but cant figure out how to get that far down the branch. I want to be able to get "description" in "myc" This is what i have:

{
"status": 0,
"result": [
    {
        "id": 20,
        "object_metadata": {
            "name": "David",
            "myc": [
                {
                    "description": "Hello world"
                },
                {
                    "description": "Goodbye World"
                }
            ]
        }
    }
]

}
1
  • Can you post your java code as well ? Commented May 2, 2014 at 3:46

3 Answers 3

1
    JSONObject obj = new JSONObject(jsonstring);
    JSONArray array =  obj.getJSONArray("result").getJSONObject(0).getJSONObject("object_metadata").getJSONArray("myc");
    for (int i = 0; i < array.length(); i++) {
        String description = array.getJSONObject(i).getString("description");
    }
Sign up to request clarification or add additional context in comments.

Comments

1

Try Google GSON. You can make a java class (or a model), implement getters and setters, and easily get and set every value. Parsing JSON via JSONObject can be frustrating when you are going to manipulate in deeper structure of the JSON specified.

Comments

0

try below code:-

try
{

    JSONObject json = new JSONObject("ur json");
    String status = json.getString("status");
    JSONArray result = json.getJSONArray("result");
    for (int i = 0; i < result.length(); i++)
    {
        JSONObject json_result = result.getJSONObject(i);
        String id = json_result.getString("id");
        JSONObject object_metadata = json_result.getJSONObject("object_metadata");
        String name = object_metadata.getString("name");
        JSONArray myc = object_metadata.getJSONArray("myc");
        for (int j = 0; j < myc.length(); j++)
        {
            JSONObject myc_value = myc.getJSONObject(i);
            String description = myc_value.getString("description");
        }
    }
}
catch (Exception e)
{
    // TODO: handle exception
    e.printStackTrace();
}

Comments

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.