热门技术

联系方式
热门技术

当前位置:主页 > 热门技术 >

Android解析中国天气网的Json数据,androidjson

发布时间:2019/01/31  作者:凯发K

Android解析中国天气网的Json数据,androidjson

在Android开发中,一般的APP都是通过获取服务器端的数据来更新UI,从服务器获取到的数据可以是Json,它的数据量要比XML要小,这里解析中国天气网上获取的数据,虽然已经不再更新了,但用来学习还是可以的,为了方便我直接到数据通过txt保存到本地,它的数据可以通过这个页面获取:http://m.weather.com.cn/data/101280601.html

目录结构

如果格式有错,会有提示,方便我们修改,有一点需要注意,创建文件保存Json数据时不能有换行

以下是错误的,这是为了我们方便理解

{
  "weatherinfo": {
    "city": "深圳",
    "city_en": "shenzhen",
    "date_y": "2014年3月4日",
    "date": "",
    "week": "星期二",
    "fchh": "11",
    "cityid": "101280601",
    "temp1": "20℃~15℃",
    "temp2": "20℃~15℃",
    "temp3": "21℃~16℃",
    "temp4": "19℃~16℃",
    "temp5": "20℃~15℃",
    "temp6": "19℃~14℃",
    "tempF1": "68℉~59℉",
    "tempF2": "68℉~59℉",
    "tempF3": "69.8℉~60.8℉",
    "tempF4": "66.2℉~60.8℉",
    "tempF5": "68℉~59℉",
    "tempF6": "66.2℉~57.2℉",
    "weather1": "多云",
    "weather2": "小雨",
    "weather3": "小雨",
    "weather4": "阴转小雨",
    "weather5": "小雨",
    "weather6": "小雨转阴",
    "凤凰娱乐网址img1": "1",
    "img2": "99",
    "img3": "7",
    "img4": "99",
    "img5": "7",
    "img6": "99",
    "img7": "2",
    "img8": "7",
    "img9": "7",
    "img10": "99",
    "img11": "7",
    "img12": "2",
    "img_single": "1",
    "img_title1": "多云",
    "img_title2": "多云",
    "img_title3": "小雨",
    "img_title4": "小雨",
    "img_title5": "小雨",
    "img_title6": "小雨",
    "img_title7": "阴",
    "img_title8": "小雨",
    "img_title9": "小雨",
    "img_title10": "小雨",
    "img_title11": "小雨",
    "img_title12": "阴",
    "img_title_single": "多云",
    "wind1": "微风",
    "wind2": "微风",
    "wind3": "东风3-4级",
    "wind4": "微风",
    "wind5": "微风",
    "wind6": "微风",
    "fx1": "微风",
    "fx2": "微风",
    "fl1": "小于3级",
    "fl2": "小于3级",
    "fl3": "3-4级",
    "fl4": "小于3级",
    "fl5": "小于3级",
    "fl6": "小于3级",
    "index": "较舒适",
    "index_d": "建议着薄外套、开衫牛仔衫裤等服装。年老体弱者应适当添加衣物,宜着夹克衫、薄毛衣等。",
    "index48": "较舒适",
    "index48_d": "建议着薄外套、开衫牛仔衫裤等服装。年老体弱者应适当添加衣物,宜着夹克衫、薄毛衣等。",
    "index_uv": "弱",
    "index48_uv": "最弱",
    "index_xc": "不宜",
    "index_tr": "适宜",
    "index_co": "舒适",
    "st1": "20",
    "st2": "15",
    "st3": "21",
    "st4": "15",
    "st5": "21",
    "st6": "14",
    "index_cl": "适宜",
    "index_ls": "适宜",
    "index_ag": "极易发"
  }
}
以下格式是才是正确的

{"weatherinfo":{"city":"深圳","city_en":"shenzhen","date_y":"2014年3月4日","date":"","week":"星期二","fchh":"11","cityid":"101280601","temp1":"20℃~15℃","temp2":"20℃~15℃","temp3":"21℃~16℃","temp4":"19℃~16℃","temp5":"20℃~15℃","temp6":"19℃~14℃","tempF1":"68℉~59℉","tempF2":"68℉~59℉","tempF3":"69.8℉~60.8℉","tempF4":"66.2℉~60.8℉","tempF5":"68℉~59℉","tempF6":"66.2℉~57.2℉","weather1":"多云","weather2":"小雨","weather3":"小雨","weather4":"阴转小雨","weather5":"小雨","weather6":"小雨转阴","img1":"1","img2":"99","img3":"7","img4":"99","img5":"7","img6":"99","img7":"2","img8":"7","img9":"7","img10":"99","img11":"7","img12":"2","img_single":"1","img_title1":"多云","img_title2":"多云","img_title3":"小雨","img_title4":"小雨","img_title5":"小雨","img_title6":"小雨","img_title7":"阴","img_title8":"小雨","img_title9":"小雨","img_title10":"小雨","img_title11":"小雨","img_title12":"阴","img_title_single":"多云","wind1":"微风","wind2":"微风","wind3":"东风3-4级","wind4":"微风","wind5":"微风","wind6":"微风","fx1":"微风","fx2":"微风","fl1":"小于3级","fl2":"小于3级","fl3":"3-4级","fl4":"小于3级","fl5":"小于3级","fl6":"小于3级","index":"较舒适","index_d":"建议着薄外套、开衫牛仔衫裤等服装。年老体弱者应适当添加衣物,宜着夹克衫、薄毛衣等。","index48":"较舒适","index48_d":"建议着薄外套、开衫牛仔衫裤等服装。年老体弱者应适当添加衣物,宜着夹克衫、薄毛衣等。","index_uv":"弱","index48_uv":"最弱","index_xc":"不宜","index_tr":"适宜","index_co":"舒适","st1":"20","st2":"15","st3":"21","st4":"15","st5":"21","st6":"14","index_cl":"适宜","index_ls":"适宜","index_ag":"极易发"}}

Demo下载:http://download.csdn.net/detail/deng0zhaotai/7741419


Android 解析这样的json数据怎解析?

简单的给你做了下解析,具体要解析到什么程度,你自己看吧。大概解析方法就是这样的:
如下:
privatevoid testJson(){
String JsonData = "[{\"id\":[\"386\",\"381\",\"379\",\"377\"],\"num\":[\"386\",\"381\",\"379\",\"377\"]},{\"id\":[\"3860\",\"3810\",\"3790\",\"3770\"],\"num\":[\"3860\",\"3810\",\"3790\",\"3770\"]}]";
JSONObject obj = null;
JSONArray jsonArary;
try {
jsonArary = new JSONArray(JsonData);
for(int i=0;i<jsonArary.length();i++){
obj = jsonArary.getJSONObject(i);
//取ID
JSONArray strID = obj.getJSONArray("id");
for(int j=0;j<strID.length();j++){
Log.v("ID:", strID.get(j).toString());
}
//取num
JSONArray strNum = obj.getJSONArray("num");
for(int k=0;k<strNum.length();k++){
Log.v("NUM:", strNum.get(k).toString());
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
 
Android数据解析 将返回的JSON数据解析为一个实体

你是不是应该把里面的数据拿出来之后再封装到实体当中啊
 

http://www.bkjia.com/Androidjc/863166.htmlwww.bkjia.comtruehttp://www.bkjia.com/Androidjc/863166.htmlTechArticleAndroid解析中国天气网的Json数据,androidjson 在Android开发中,一般的APP都是通过获取服务器端的数据来更新UI,从服务器获取到的数据可以是...

本文源自: AG环亚集团官网

AG环亚集团官网_AG亚游平台_AG8环亚集团_腾讯财经 | 热门技术 | IT技术新闻 | IT技术分享 | 开发者平台 |

Copyright © 2005-2016 http://www.simoneloru.com AG环亚集团官网_AG亚游平台_AG8环亚集团_腾讯财经版权所有 AG环亚集团官网_AG亚游平台_AG8环亚集团_腾讯财经