java 解析json api_java web api json 数据解析

1、jar 包

JSONObject 类需要导入两个json 包

1.1、json-20160810.jar

1.2、commons-io-2.4.jar

File file = new File("C:" + File.separator + "curtis" + File.separator + "java" + File.separator + "demo"

+ File.separator + "JavaSE-01" + File.separator + "src" + File.separator + "weather.json");

String content = FileUtils.readFileToString(file);

JSONObject obj = new JSONObject(content);

// System.out.println(obj);

JSONObject today = obj.getJSONObject("result").getJSONObject("today");

// System.out.println(obj.getJSONObject("result").getJSONObject("today"));

System.out.print(today.getString("city") + " ");

System.out.print(today.getString("week") + " ");

System.out.print(today.getString("temperature"));

{

"resultcode": "200",

"reason": "successed!",

"result": {

"sk": {

"temp": "9",

"wind_direction": "东北风",

"wind_strength": "3级",

"humidity": "79%",

"time": "14:15"

},

"today": {

"temperature": "5℃~12℃",

"weather": "中雨转小雨-中雨",

"weather_id": {

"fa": "08",

"fb": "21"

},

"wind": "北风4-5 级",

"week": "星期一",

"city": "广州",

"date_y": "2018年01月08日",

"dressing_index": "较冷",

"dressing_advice": "建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。",

"uv_index": "最弱",

"comfort_index": "",

"wash_index": "不宜",

"travel_index": "较不宜",

"exercise_index": "较不宜",

"drying_index": ""

},

"future": [

{

"temperature": "5℃~12℃",

"weather": "中雨转小雨-中雨",

"weather_id": {

"fa": "08",

"fb": "21"

},

"wind": "北风4-5 级",

"week": "星期一",

"date": "20180108"

},

{

"temperature": "5℃~8℃",

"weather": "小雨转阴",

"weather_id": {

"fa": "07",

"fb": "02"

},

"wind": "北风3-4 级",

"week": "星期二",

"date": "20180109"

},

{

"temperature": "6℃~14℃",

"weather": "多云",

"weather_id": {

"fa": "01",

"fb": "01"

},

"wind": "北风3-4 级",

"week": "星期三",

"date": "20180110"

},

{

"temperature": "8℃~15℃",

"weather": "多云",

"weather_id": {

"fa": "01",

"fb": "01"

},

"wind": "微风",

"week": "星期四",

"date": "20180111"

},

{

"temperature": "9℃~16℃",

"weather": "多云",

"weather_id": {

"fa": "01",

"fb": "01"

},

"wind": "微风",

"week": "星期五",

"date": "20180112"

},

{

"temperature": "8℃~15℃",

"weather": "多云",

"weather_id": {

"fa": "01",

"fb": "01"

},

"wind": "微风",

"week": "星期六",

"date": "20180113"

},

{

"temperature": "5℃~8℃",

"weather": "小雨转阴",

"weather_id": {

"fa": "07",

"fb": "02"

},

"wind": "北风3-4 级",

"week": "星期日",

"date": "20180114"

}

]

},

"error_code": 0

}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值