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
}
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦