Hey guys,
I am new to JSON parsing and POJOs and need some help. I used http://www.jsonschema2pojo.org/ to convert the JSON response to POJO, which resulted in a lot of POJOs. I am then using GSON to parse the JSON response to an object (or array of objects). How do I convert this giant JSON response in to usable data? I would love to see some code snippets or examples if possible but I know that is asking a lot.
Thank you!
I don’t have time at this moment to go into really deep detail right now but thought this might help:
this uses org.json.JSONObject;
> JSONObject jsonObject = new JSONObject();
> HttpClient httpclient = HttpClients.createDefault();
> try {
> URIBuilder builder = new URIBuilder(HALO_API_ROOT_URL + “/stats/h5/servicerecords/arena?players=” + gamertag);
>
> URI uri = builder.build();
> HttpGet request = new HttpGet(uri);
> request.setHeader(“Ocp-Apim-Subscription-Key”, PRIMARY_API_KEY);
>
> HttpResponse response = httpclient.execute(request);
> HttpEntity entity = response.getEntity();
>
> if (entity != null) {
> String jsonString = EntityUtils.toString(entity);
> jsonObject = new JSONObject(jsonString);
> JSONArray results = jsonObject.getJSONArray(“Results”);
> for (int i = 0; i < results.length(); i++) {
> JSONObject result = results.getJSONObject(i);
> jsonObject = result.getJSONObject(“Result”);
> }
> JSONObject arenaStats = jsonObject.getJSONObject(“ArenaStats”);
> Integer spartanKills = arenaStats.getInt(“TotalSpartanKills”);
> Integer myDeaths = arenaStats.getInt(“TotalDeaths”);
> }
> } catch (Exception e) {
> //DoWhateverHere
> }