brackets编写java,Parsing JSON double brackets with Java

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值