I'm having some trouble as I've hit a roadblock in learning how to parse JSON with json simple.
To make myself concise;
I am trying to parse this bit of JSON from a url
"hourly": {
"summary": "Clear throughout the day.",
"icon": "clear-day",
"data": [
{
"time": 1550379600,
"summary": "Clear",
"icon": "clear-day",
"precipIntensity": 0,
"precipProbability": 0,
"temperature": 20.18,
"apparentTemperature": 14.31,
"dewPoint": 13.79,
"humidity": 0.76,
"pressure": 1024.47,
"windSpeed": 4.08,
"windGust": 5.25,
"windBearing": 30,
"cloudCover": 0.07,
"uvIndex": 0,
"visibility": 10,
"ozone": 342.67
}
so, in using json simple, this is how I am parsing this JSON
try{
String genreJson = IOUtils.toString(new URL(url));
JSONObject genreJsonObject = (JSONObject) JSONValue.parseWithException(genreJson);
//get the title
System.out.println(genreJsonObject.get("hourly")); //THIS WORKS
//System.out.println(genreJsonObject.get("visibility"));
//get the data
JSONArray genreArray = (JSONArray) genreJsonObject.get(0);
//get the first genre
//JSONObject firstGenre = (JSONObject) genreArray.get(0);
//System.out.println(firstGenre.get("data"));
}
catch (IOException | ParseException e){
e.printStackTrace();
}
So, in calling System.out.println(genreJsonObject.get("hourly")); I get everything within the brackets titled "hourly". My intent is to parse for the data within the "hourly" bracket, although I can't figure out how to parse for a title within a titled bracket. Specifically, I need the time, the precipProbability, precipIntensity, and precipProbability (this attribute is not in the example).
I apologize for any lack of detail as I'm doing this as part my first hackathon, and I'm trying not to fall asleep right now.
I greatly appreciate anyone's help.