0 points

How to parse JSON in Java


dashboard

Thu Dec 26 2019 16:01:30 GMT+0000 (UTC)

Posted by @mishka #java #howto #json

import org.json.*;


JSONObject obj = new JSONObject(" .... ");
String pageName = obj.getJSONObject("pageInfo").getString("pageName");

JSONArray arr = obj.getJSONArray("posts");
for (int i = 0; i < arr.length(); i++)
{
    String post_id = arr.getJSONObject(i).getString("post_id");
    ......
}
content_copy Copy

Using the org.json library: https://github.com/stleary/JSON-java Downloadable jar: http://mvnrepository.com/artifact/org.json/json

https://stackoverflow.com/questions/2591098/how-to-parse-json-in-java