JSON parsing to Java - Android application -


i need parsing json string in java android appl.

text of json file:

{"data":{"columns":["location_id","name","description","latitude","longitude","error","type","type_id","icon_media_id","item_qty","hidden","force_view"],"rows":[[2,"editor","",43.076014654537,-89.399642451567,25,"npc",1,0,1,"0","0"],[3,"dow recruiter","",43.07550842555,-89.399381822662,25,"npc",2,0,1,"0","0"] [4,"protestor","",43.074933,-89.400438,25,"npc",3,0,1,"0","0"],[5,"state legislator","",43.074868061524,-89.402136196317,25,"npc",4,0,1,"0","0"],[6,"marchers bascom","",43.075296413877,-89.403374183615,25,"node",22,0,1,"0","0"] [7,"mary","",43.074997865584,-89.404967573966,25,"npc",7,0,1,"0","0"]]},"returncode":0,"returncodedescription":null} 

how can values: location_id, name, latitude, longitude. thanks, michal.

using manual parsing can implement this:

            jsonarray  pages     =  new jsonarray(jsonstring);             (int = 0; < pages.length(); ++i) {                 jsonobject rec = pages.getjsonobject(i);                 jsonobject jsonpage =rec.getjsonobject("page");                 string address = jsonpage.getstring("url");                 string name = jsonpage.getstring("name");                 string status =  jsonpage.getstring("status"); } 

in case note outer elemnt data type of jsonobject , have jsonarray

mine json file:

[{"page":{"created_at":"2011-07-04t12:01:00z","id":1,"name":"unknown page","ping_at":"2011-07-04t12:06:00z","status":"up","updated_at":"2011-07-04t12:01:00z","url":"http://www.iana.org/domains/example/","user_id":2}},{"page":{"created_at":"2011-07-04t12:01:03z","id":3,"name":"down page","ping_at":"2011-07-04t12:06:03z","status":"up","updated_at":"2011-07-04t12:01:03z","url":"http://www.iana.org/domains/example/","user_id":2}}]  

note mine starts [, means array, yours { , have [ array inside. if run debugger, can see what´s inside json objects.

there better approaches like:

  1. jackson
  2. jackson-jr (light-weight jackson)
  3. gson

all of them can used convert java objects json representation. can used convert json string equivalent java object.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -