"future":{
"day_20160525":{
"temperature":"17℃~28℃",
"weather":"多云转晴",
"weather_id":{
"fa":"01",
"fb":"00"
},
"wind":"南风3-4 级",
"week":"星期三",
"date":"20160525"
},
"day_20160526":{
"temperature":"16℃~30℃",
"weather":"晴",
"weather_id":{
"fa":"00",
"fb":"00"
},
"wind":"北风4-5 级",
"week":"星期四",
"date":"20160526"
},
"day_20160527":{
"temperature":"18℃~32℃",
"weather":"晴",
"weather_id":{
"fa":"00",
"fb":"00"
},
"wind":"南风3-4 级",
"week":"星期五",
"date":"20160527"
},
"day_20160528":{
"temperature":"19℃~30℃",
"weather":"晴转多云",
"weather_id":{
"fa":"00",
"fb":"01"
},
"wind":"微风",
"week":"星期六",
"date":"20160528"
},
"day_20160529":{
"temperature":"19℃~31℃",
"weather":"晴转多云",
"weather_id":{
"fa":"00",
"fb":"01"
},
"wind":"微风",
"week":"星期日",
"date":"20160529"
},
"day_20160530":{
"temperature":"18℃~32℃",
"weather":"晴",
"weather_id":{
"fa":"00",
"fb":"00"
},
"wind":"南风3-4 级",
"week":"星期一",
"date":"20160530"
},
"day_20160531":{
"temperature":"19℃~30℃",
"weather":"晴转多云",
"weather_id":{
"fa":"00",
"fb":"01"
},
"wind":"微风",
"week":"星期二",
"date":"20160531"
}
}
},
关于这一段JSon应该如何解析?不能解析成数组,查询未来六日的日期,如果解析成对象,那就
需要写入每日的日期,这样又比较麻烦,请问有没有一些办法进行简单的解析,解析出未来六日
的一些天气信息?望大神帮忙
关于Json解析问题,求大神帮忙
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
8条回答 默认 最新
「已注销」 2016-05-25 08:33关注#如下是您提供的结构体# { "future": { "day_20160525": { "temperature": "17℃~28℃", "weather": "多云转晴", "weather_id": { "fa": "01", "fb": "00" }, "wind": "南风3-4 级", "week": "星期三", "date": "20160525" }, "day_20160526": { "temperature": "16℃~30℃", "weather": "晴", "weather_id": { "fa": "00", "fb": "00" }, "wind": "北风4-5 级", "week": "星期四", "date": "20160526" } } }- 您提供的JSON串中future的值被“{}”包含,所以future本身是一个对象,并非数组。只是future的值包含多个日期的天气数据,所以会被误解为数组形式。
- 重点强调:此JSON数据结构设计得比较糟糕,将
day_20160525,day_20160526等这类动态的值作为属性名称,非常不利于制造数据方人员的JSON构造,也不利于解析数据方人员的JSON解析。 - JSON结构的良好设计方式:**不要将属性名称设计为动态的值**。建议改造为如下两种结构之一:
#如下是我建议改造之后的结构体(一)# { "future": [ { "date": "20160525", "value": { "temperature": "17℃~28℃", "weather": "多云转晴", "weather_id": { "fa": "01", "fb": "00" }, "wind": "南风3-4 级", "week": "星期三" } }, { "date": "20160526", "value": { "temperature": "16℃~30℃", "weather": "晴", "weather_id": { "fa": "00", "fb": "00" }, "wind": "北风4-5 级", "week": "星期四" } } ] }#如下是我建议改造之后的结构体(二)# { "future": [ { "temperature": "17℃~28℃", "weather": "多云转晴", "weather_id": { "fa": "01", "fb": "00" }, "wind": "南风3-4 级", "week": "星期三", "date": "20160525" }, { "temperature": "16℃~30℃", "weather": "晴", "weather_id": { "fa": "00", "fb": "00" }, "wind": "北风4-5 级", "week": "星期四", "date": "20160526" } ] }祝您一切顺利!
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报