3

I want below process on with out editing on server side

I followed this example

but over there he is calling data with one json object from a url

called "worldpopulation",..

but i have a Json data which is having lot of Json objects and arrays,.. like below code

{ "getting data":"ok"
   "Todays":population
   {"results"{[
   "worldpopulation": 
[
     {
     "rank":1,"country":"China",
     "population":"1,354,040,000",
     "flag":["http://www.androidbegin.com/tutorial/flag/china.png"]
     }, 
{
    "population":{
     [
    "countrypulation"        {
     "rank":2,"country":"India",
     "population":"1,210,193,422",
     "flag":["http://www.androidbegin.com/tutorial/flag/india.png"]
     }, 

like that i have a lot of data i want this data in that above example. Without changing any thing on server side,.. or Restful service,.. thank you

2
  • refer to stackoverflow.com/questions/20492940/… Commented Dec 11, 2013 at 7:48
  • hellow ravneet sir yesterday its not worked for me,... please do this how it work on above example and mail me,.. please sir... Commented Dec 11, 2013 at 7:50

2 Answers 2

3

response

JSONObject JObject = new JSONObject(response);
      String getting_data = JObject.getstring("getting data");
    String Todays= JObject.getstring("Todays");
    JsonArray results =JObject.getjsonarray("results");
    for(int i = 0 ; i < results.length(); i++){
     JsonObject resultsobject =results.getjsonobject(i);

    JsonArray worldpopulation 
=resultsobject.getjsonarray("worldpopulation");
         for(int j = 0 ; j < worldpopulation.length(); j++){
     JsonObject worldpopulationobject =worldpopulation.getjsonobject(j);
     JsonObject emptyobject =worldpopulationobject.getjsonobject("");
         String rank=emptyobject .getstring("rank"); 
        String population=emptyobject .getstring("population"); 
        JsonArray flagarray =countrypulation.getjsonarray(flag);
        for(int n = 0 ; n < flagarray.length(); n++){
        JsonObject flagarrayobject =flag1array.getjsonobject(n);
        String flag=flag1arrayobject .getstring("flag"); 
        }

     JsonObject populationobject 
=worldpopulationobject.getjsonobject("population");
         JsonArray emptyarray =JObject.getjsonarray("");
    for(int k = 0 ; k < emptyarray.length(); k++){
        JsonObject emptyarrayobject =emptyarray.getjsonobject(k);
        JsonObject 
countrypulation=emptyarrayobject.getjsonobject("countrypulation");

         String rank1=countrypulation .getstring("rank"); 
        String country=countrypulation .getstring("country"); 
        String population1=countrypulation .getstring("population");
        JsonArray flag1array =countrypulation.getjsonarray(flag);
        for(int m = 0 ; m < flag1array.length(); m++){
        JsonObject flag1arrayobject =flag1array.getjsonobject(m);
        String flag1=flag1arrayobject .getstring("flag"); 
        }
    }
    }
    }
Sign up to request clarification or add additional context in comments.

3 Comments

hellow ravneeth sir i am not using this like in my server... JSONObject JObject = new JSONObject(response);
@user2967727 well, response is a string here, in which all the response coming from server is put. He assumes that you have all of that response in string named "response" and then he parse that.
Yes that is how i did.
1

You parse

{
    ...
}

as JSONObject and

[
    ...
]

as JSONArray. JSONArray contains your objects. From the JSONObject you can retrieve the property values.

JSONArray response = new JSONArray('your json string');

for (int i = 0; i < response.length(); i++) {
    response.getJSONObject(i).getString("property"));
}

BTW your json is invalid, event if you close the missing brackets. Check it here http://jsonlint.com/

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.