JSONObject cannot be converted to JSONArray

来源:互联网 发布:淘宝店铺简介怎么修改 编辑:程序博客网 时间:2024/05/20 11:50
错误信息:org.json.JSONException: Value {"weatherinfo":{"city":"石家庄","cityid":"101090101","temp1":"2","temp2":"19","weather":"晴","img1":"n0.gif","img2":"d0.gif","ptime":"18:00"}} of type org.json.JSONObject cannot be converted to JSONArray

数据是 {"weatherinfo":{"city":"石家庄","cityid":"101090101","temp1":"2","temp2":"19","weather":"晴","img1":"n0.gif","img2":"d0.gif","ptime":"18:00"}}
数据地址:http://www.weather.com.cn/data/cityinfo/101090101.html

public static List<Weathers> getData(InputStream inputStream) throws IOException, JSONException {
        byte[] data = StreamTools.read(inputStream);
        JSONArray array = new JSONArray(new String(data));
        List<Weathers> list = new ArrayList<Weathers>();
        for (int i = 0; i < array.length(); i++ ){
            JSONObject object =array.getJSONObject(i);
            Weathers wea = new Weathers(object.getString("city"),
                    object.getString("cityid"),
                    object.getString("temp1"),
                    object.getString("temp2"),
                    object.getString("weather"),
                    object.getString("img1"),
                    object.getString("img2"),
                    object.getString("ptime"));
            Log.i("NetJsonService","Weathers="+wea.toString());
            list.add(wea);
        }
        return list;
    }


是不是因为这个json格式有问题?求大神解救!该如何解析这个json?
0 0