最新最全天气预报附带Json解析

http://wthrcdn.etouch.cn/weather_mini?city=101010100

{"desc":"OK","status":1000,"data":{"wendu":"24","ganmao":"天气转凉,空气湿度较大,较易发生感冒,体质较弱的朋友请注意适当防护。","forecast":[{"fengxiang":"无持续风向","fengli":"微风级","high":"高温 26℃","type":"雷阵雨","low":"低温 18℃","date":"13日星期三"},{"fengxiang":"无持续风向","fengli":"微风级","high":"高温 26℃","type":"阵雨","low":"低温 19℃","date":"14日星期四"},{"fengxiang":"无持续风向","fengli":"微风级","high":"高温 22℃","type":"小到中雨","low":"低温 19℃","date":"15日星期五"},{"fengxiang":"无持续风向","fengli":"微风级","high":"高温 24℃","type":"雷阵雨","low":"低温 16℃","date":"16日星期六"},{"fengxiang":"北风","fengli":"3-4级","high":"高温 24℃","type":"多云","low":"低温 15℃","date":"17日星期天"}],"yesterday":{"fl":"微风","fx":"无持续风向","high":"高温 26℃","type":"雷阵雨","low":"低温 18℃","date":"12日星期二"},"aqi":"81","city":"南昌"}}

{" weatherinfo ":{" city ":"北京"," cityid ":"101010100"," temp1 ":"15℃","temp2":"5℃","weather":"多云","img1":"d1.gif","img2":"n1.gif","ptime":"08:00"}}

new Thread() {
            public void run() {
                try {
                    Map map = new HashMap();
                    String str = HttpUtil.doGet(
                            url1 = "http://www.weather.com.cn/adat/cityinfo/"
                                    + cityid+ ".html", map);
                    // 将string转换为jsonobject
                    JSONObject jsonObject0 = new JSONObject(str);
                    // 解析jsonobject里面的值
                    JSONObject jsonObject1 = jsonObject0
                            .getJSONObject("weatherinfo");
                    city_ = jsonObject1.getString("city");
                    cityid_ = jsonObject1.getString("cityid");
                    temp2_ = jsonObject1.getString("temp2");
                    temp1_ = jsonObject1.getString("temp1");
                    weather_ = jsonObject1.getString("weather");
                    ptime_ = jsonObject1.getString("ptime");
                    handler.sendEmptyMessage(1)
                    } catch (Exception e) {
                    e.printStackTrace();
                    handler.sendEmptyMessage(2);
                }
            };
        }.start();

你可能感兴趣的:(android)