java - How to parse JSON -


i have following json text need parse pagename, pagepic, post_id, etc.

what required code?

{    "pageinfo": {          "pagename": "abc",          "pagepic": "http://example.com/content.jpg"     }     "posts": [          {               "post_id": "123456789012_123456789012",               "actor_id": "1234567890",               "picofpersonwhoposted": "http://example.com/photo.jpg",               "nameofpersonwhoposted": "jane doe",               "message": "sounds cool. can't wait see it!",               "likescount": "2",               "comments": [],               "timeofpost": "1234567890"          }     ] } 

the org.json library easy use. example code below:

import org.json.*;   jsonobject obj = new jsonobject(" .... "); string pagename = obj.getjsonobject("pageinfo").getstring("pagename");  jsonarray arr = obj.getjsonarray("posts"); (int = 0; < arr.length(); i++) {     string post_id = arr.getjsonobject(i).getstring("post_id");     ...... } 

you may find examples from: parse json in java

downloadable jar: http://mvnrepository.com/artifact/org.json/json


Comments