关于解析json数组中的json数组
来源:互联网 发布:复式组合软件 编辑:程序博客网 时间:2024/06/06 02:38
大多数的人应该都知道怎么解析json数组,可今天却遇到一个json数组里面嵌套json数组的情况,废话不多说,上代码
JSONObject root = new JSONObject(jsondata);
JSONArray array1=root.getJSONArray("weather");//先将jsondata里面的weather数组提取出来
String dsa=array1.toString();
String asd=dsa.substring(1, dsa.length()-1);//这是最关键的,将weather的value去除【】后变成一个新的json 格式字符串,缺少这一步运行时会报错
JSONObject rJsonObject=new JSONObject(asd);//继续按照解析jsonarray的方式解析
JSONArray array=rJsonObject.getJSONArray("future");
for (int i = 0; i < array.length(); i++) {
JSONObject lan=array.getJSONObject(i);
System.out.println(lan.getString("date"));
System.out.println(lan.getString("day"));
}
jsondata的内容:
{"status":"OK","weather":[{"city_name":"北京","city_id":"CHBJ000000","last_update":"2015-05-06T22:58:53+08:00","future":[{"date":"2015-05-06","day":"周三","text":"小雨","code1":"13","code2":"13","high":"25","low":"11","cop":"0%","wind":"南风3~4级"},{"date":"2015-05-07","day":"周四","text":"晴/阵雨","code1":"0","code2":"10","high":"25","low":"14","cop":"0%","wind":"北风3~4级转微风小于3级"}]}]}
0 0
- 关于解析json数组中的json数组
- json 解析 数组中的对象
- 关于数组类型的json解析方法
- json json数组,json字符串解析
- Flex解析Json数组
- 解析json数组
- json数组解析
- JSON数组解析
- JSON解析数组
- android解析json数组
- android解析JSON数组
- java解析json数组
- Json解析数组实例
- Gson解析json数组
- 解析 json 数组
- Gson解析json数组
- 解析json数组
- PHP 解析JSON数组
- greenplum的扩容(1)-前期准备
- 实现类似于QQ空间相册的点击图片放大,再点后缩小回原来位置
- 使用Xamarin + C#开发应用 -- 使用sqlite做本地存储
- 作为计算机专业学生,最应该学习的课程前五位是什么?【知乎】
- C++标准转换运算符static_cast
- 关于解析json数组中的json数组
- Mac下PHP环境搭建
- HDU 5214 MOVIE
- python写的二分查找
- Caused by: java.net.SocketException: Software caused connection abort: socket write error
- 位运算+枚举
- PHP单文件上传原理及上传函数的封装
- java Fork/Join框架实例详解
- 我用Cocos2d-x模拟《Love Live!学院偶像祭》的Live场景(一)