Iraj
Iraj

Reputation: 1

Android studio: How to receive Json Volley with different objects

According to this json file I want to receive data1 , xyz, abc object and their sub objects and show it in recyclerview.But I am receiving only data1 and their key-value pairs(index1 and name). I am using library Volley. Can someone help me how to recive xyz and abc ?

 {
"Data1":{
       "index1":"4",
       "name":"dan"
     },
"xyz":{
       "index1":"2",
       "name":"jimi"
     }
"abc":{
       "index1":"5",
       "name":"jordan"
     }
}

JSONObject jsonObject = response.getJSONObject("Data1");
getset1.seti(jsonObject.getString("index1"));
getset1.setn(jsonObject.getString("name"));

Upvotes: 0

Views: 57

Answers (2)

Wahdat Jan
Wahdat Jan

Reputation: 4156

Try this

            JSONObject jsonobject=new JSONobject("");
                   for (int i=0;i<jsonobject.length();i++){
                       JSONObject jsonObject1=jsonobject.getJSONObject(i);

                              );

Upvotes: 1

Md.ibrahim khalil
Md.ibrahim khalil

Reputation: 479

You have to use loop.As this is not an array so u have to fetch the all keys using iterator and then loop among them try this

Iterator<String> keys = json.keys();

while (keys.hasNext())
{
    // Get the key
    String key = keys.next();

    // Get the value
    JSONObject value = json.getJSONObject(key);

    // parse inner string from value
} 

Upvotes: 0

Related Questions