JSONParser java parse int code example
Example 1: how to parse json in java
import org.json.*;
String jsonString = ... ;
JSONObject obj = new JSONObject(jsonString);
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");
......
}
Example 2: org.json.simple.JSONobject get integer
public static Update fromString(String json) {
try {
JSONObject obj = (JSONObject) new JSONParser().parse(json);
int buildNumber = ((Long) obj.get("buildNumber")).intValue();
URL download = new URL((String) obj.get("download"));
return new Update(buildNumber, download, true);
} catch (IOException | ParseException ex) {
Log.e(TAG, "Invalid JSON object: " + json);
}
return new Update(0, null, true);
}
}