-2

Hello friends this is my json data:

{
   "menus":[
      {
         "id":15,
         "color":"#A67A37",
         "communications":[
            {
               "id":16,
               "projectname":"Sales Training",
               "showpdfprint":false,
               "sendcategory":"document",
               "opened":1
            }
         ],
         "seminars":[

         ],
         "name":"Selective Retail Academy"
      }      "communications":[
         {
            "id":17,
            "projectname":"Sales Education",
            "showpdfprint":false,
            "sendcategory":"document",
            "opened":1
         }
      ],
      "seminars":[

      ],
      "name":"Retail Academy"
   }
}
]

I want to retrieve communication Array providing name ,How can I achieve this in android

GuilhE
  • 11,591
  • 16
  • 75
  • 116

2 Answers2

0

Using the org.json library:

JSONObject jObject = new JSONObject(jsonContent); //jsonContent is your content above as a string

JSONArray jArray = jObject.getJSONArray("menus");
JSONArray result;
for(JSONObject jObj : jArray){
    if(jObj.getString("name").equals(givenName){ //givenName is the name you are looking for
        result = jObj.getJSONArray("communications");
    }
}

You can then do what you like with the communications JSONArray stored in "result."

You can see more on the org.json library here: http://www.json.org/javadoc/org/json/package-summary.html

vontell
  • 342
  • 3
  • 17
  • If this worked for you, please mark as correct answer :) – vontell Jul 08 '15 at 16:36
  • 1
    Thanks. this code help me lots, I edit this code like this JSONArray jsonArray = jsonObjec.getJSONArray("menus"); for (int i = 0; i < jsonArray.length(); i++) { JSONArray Communications = null; String name = jsonArray1.getJSONObject(i).getString("name"); if(name.equals(givenName)) { Communications = jsonArray.getJSONObject(i).getJSONArray("communications");} – Nilesh Bhadane Jul 09 '15 at 03:10
-1

Try this Pseudo Code JSON Object

Think that is Pseudo code for java

eddykordo
  • 607
  • 5
  • 14