0

My json output is as follows:

http://tinyurl.com/qceyd2z

How to parse it in Android?

I have been using iteration to loop over object collection1 without success. I want to access my array collection1 under object result:

if (jsonStr != null) {
    try {
        JSONObject jsonObj = new JSONObject(jsonStr);

        // Getting JSON Array node
        contacts = jsonObj.getJSONArray(TAG_CONTACTS);

        // looping through All Contacts
        for (int i = 0; i < contacts.length(); i++) {
            JSONObject c = contacts.getJSONObject(i);

            String id = c.getString(string1);
            String name = c.getString(string2);
            String email = c.getString(string3);
            String address = c.getString(string4);
            String gender = c.getString(string5);
            ...
1
  • Try to include more code, i.e. how do you get the jsonStr and at least complete the code snippet you included. Commented Mar 12, 2015 at 11:31

2 Answers 2

1

This may help you:

if (jsonStr != null) {
  try {
       JSONObject jsonObj = new JSONObject(jsonStr);

       JSONObject jsonResult=jsonObj.getJSONObject("results");
   JSONArray jsonArrayCollection=jsonResult.getJSONArray("collection1");

       // looping through All Collection
       for (int i = 0; i < jsonArrayCollection.length(); i++) {
             JSONObject collctns = jsonArrayCollection.getJSONObject(i);
             String prop1Href=collctns.getJSONObject("property1").getString("href");
             String prop1Text=collctns.getJSONObject("property1").getString("text");
             String prop2=collctns..getString("property2")
      } 
  }catch(JSONException e){
     e.printStaceTrace();
  }
}
Sign up to request clarification or add additional context in comments.

Comments

0

Use Libraries Like GSON That will save u lot of time in parsing JSON data... here is a sample tutorial to get started..

Tutorial : link

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.