How to parse JSON in Java

PHOTO EMBED

Thu Dec 26 2019 16:01:30 GMT+0000 (Coordinated Universal Time)

Saved 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_copyCOPY

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