FocusOn 发表于 2020-5-29 15:02:47

json数据解析

从api返回的json数据,如何读取自己需要的数据,比如图片的json格式,我想读取pm2.5和pm10的值{
                  "showapi_res_error": "",
                  "showapi_res_id": "6cb96fedf90a486da298b139ffbea99f",
                  "showapi_res_code": 0,
                  "showapi_res_body": {"ret_code":0,"showapi_fee_code":-1,"pm":{"so2":"8","o3":"42","area_code":"tianjin","pm2_5":"30","ct":"2019-12-13 16:00:42.793","primary_pollutant":"颗粒物(PM10)","co":"0.6","num":"83","area":"天津","no2":"35","aqi":"51","quality":"良好","pm10":"51","o3_8h":"33"},"siteList":[{"co":"1.2","so2":"22","o3":"32","no2":"62","aqi":"107","quality":"轻度污染","pm10":"119","pm2_5":"80","site_name":"广安道","o3_8h":"14","primary_pollutant":"-","ct":"2019-12-13 15:03:29.194"},{"co":"0.7","so2":"13","o3":"32","no2":"50","aqi":"84","quality":"良好","pm10":"55","pm2_5":"62","site_name":"永明路","o3_8h":"11","primary_pollutant":"PM2.5","ct":"2019-12-13 15:03:29.602"},{"co":"0.8","so2":"12","o3":"32","no2":"53","aqi":"82","quality":"良好","pm10":"-","pm2_5":"60","site_name":"海泰发展二路","o3_8h":"38","primary_pollutant":"-","ct":"2019-12-13 15:03:29.621"},{"co":"0.7","so2":"14","o3":"24","no2":"50","aqi":"82","quality":"良好","pm10":"66","pm2_5":"60","site_name":"塘沽营口道","o3_8h":"9","primary_pollutant":"-","ct":"2019-12-13 15:03:29.634"},{"co":"0.4","so2":"6","o3":"43","no2":"27","aqi":"82","quality":"良好","pm10":"75","pm2_5":"60","site_name":"滨水东路","o3_8h":"17","primary_pollutant":"-","ct":"2019-12-13 15:03:29.652"},{"co":"0.7","so2":"12","o3":"36","no2":"45","aqi":"77","quality":"良好","pm10":"68","pm2_5":"56","site_name":"汉北路","o3_8h":"12","primary_pollutant":"PM2.5","ct":"2019-12-13 15:03:29.661"},{"co":"0.9","so2":"14","o3":"28","no2":"49","aqi":"75","quality":"良好","pm10":"72","pm2_5":"55","site_name":"第四大街","o3_8h":"12","primary_pollutant":"PM2.5","ct":"2019-12-13 15:03:29.666"},{"co":"0.7","so2":"23","o3":"25","no2":"54","aqi":"73","quality":"良好","pm10":"72","pm2_5":"53","site_name":"团泊洼(对照点)","o3_8h":"11","primary_pollutant":"PM2.5","ct":"2019-12-13 15:03:29.673"},{"co":"0.7","so2":"13","o3":"36","no2":"44","aqi":"69","quality":"良好","pm10":"69","pm2_5":"50","site_name":"河西一经路(启用150702)","o3_8h":"16","primary_pollutant":"PM2.5","ct":"2019-12-13 15:03:29.678"},{"co":"0.7","so2":"11","o3":"32","no2":"45","aqi":"63","quality":"良好","pm10":"56","pm2_5":"45","site_name":"宾水西道(启用150702)","o3_8h":"14","primary_pollutant":"PM2.5","ct":"2019-12-13 15:03:29.685"},{"co":"0.7","so2":"11","o3":"34","no2":"53","aqi":"62","quality":"良好","pm10":"62","pm2_5":"44","site_name":"津沽路(启用150702)","o3_8h":"15","primary_pollutant":"PM2.5","ct":"2019-12-13 15:03:29.691"},{"co":"0.7","so2":"12","o3":"35","no2":"58","aqi":"62","quality":"良好","pm10":"63","pm2_5":"44","site_name":"跃进路","o3_8h":"14","primary_pollutant":"PM2.5","ct":"2019-12-13 15:03:29.700"},{"co":"0.5","so2":"5","o3":"40","no2":"29","aqi":"60","quality":"良好","pm10":"69","pm2_5":"42","site_name":"宝白公路","o3_8h":"19","primary_pollutant":"PM10","ct":"2019-12-13 15:03:29.706"},{"co":"1.0","so2":"12","o3":"33","no2":"43","aqi":"58","quality":"良好","pm10":"55","pm2_5":"41","site_name":"大理道(启用160601)","o3_8h":"14","primary_pollutant":"PM2.5","ct":"2019-12-13 15:03:29.711"},{"co":"0.9","so2":"10","o3":"32","no2":"38","aqi":"58","quality":"良好","pm10":"59","pm2_5":"41","site_name":"地纬路","o3_8h":"33","primary_pollutant":"-","ct":"2019-12-13 15:03:29.717"},{"co":"0.5","so2":"11","o3":"35","no2":"37","aqi":"54","quality":"良好","pm10":"58","pm2_5":"34","site_name":"淮河路","o3_8h":"14","primary_pollutant":"PM10","ct":"2019-12-13 15:03:29.724"},{"co":"0.7","so2":"9","o3":"35","no2":"36","aqi":"54","quality":"良好","pm10":"48","pm2_5":"38","site_name":"天和路","o3_8h":"14","primary_pollutant":"-","ct":"2019-12-13 15:03:29.731"},{"co":"0.5","so2":"11","o3":"35","no2":"37","aqi":"54","quality":"良好","pm10":"58","pm2_5":"34","site_name":"淮河道","o3_8h":"14","primary_pollutant":"PM10","ct":"2019-12-13 15:03:29.737"},{"co":"0.6","so2":"6","o3":"38","no2":"36","aqi":"53","quality":"良好","pm10":"54","pm2_5":"37","site_name":"西四道(启用170426)","o3_8h":"14","primary_pollutant":"PM2.5","ct":"2019-12-13 15:03:29.744"},{"co":"0.6","so2":"7","o3":"33","no2":"50","aqi":"52","quality":"良好","pm10":"52","pm2_5":"36","site_name":"大直沽八号路","o3_8h":"15","primary_pollutant":"PM2.5","ct":"2019-12-13 15:03:29.749"},{"co":"0.9","so2":"9","o3":"-","no2":"40","aqi":"52","quality":"良好","pm10":"54","pm2_5":"32","site_name":"辛老路","o3_8h":"4","primary_pollutant":"PM10","ct":"2019-12-13 15:03:29.755"},{"co":"0.7","so2":"6","o3":"31","no2":"36","aqi":"50","quality":"优质","pm10":"50","pm2_5":"29","site_name":"勤俭道","o3_8h":"14","primary_pollutant":"-","ct":"2019-12-13 15:03:29.760"},{"co":"0.7","so2":"6","o3":"31","no2":"36","aqi":"50","quality":"优质","pm10":"50","pm2_5":"29","site_name":"勤俭路","o3_8h":"14","primary_pollutant":"-","ct":"2019-12-13 15:03:29.766"},{"co":"0.9","so2":"7","o3":"38","no2":"43","aqi":"48","quality":"优质","pm10":"44","pm2_5":"33","site_name":"前进道","o3_8h":"17","primary_pollutant":"-","ct":"2019-12-13 15:03:29.771"},{"co":"0.9","so2":"7","o3":"38","no2":"43","aqi":"48","quality":"优质","pm10":"44","pm2_5":"33","site_name":"前进路","o3_8h":"17","primary_pollutant":"-","ct":"2019-12-13 15:03:29.776"},{"co":"0.6","so2":"7","o3":"35","no2":"46","aqi":"47","quality":"优质","pm10":"47","pm2_5":"-","site_name":"中山北路(启用161122)","o3_8h":"16","primary_pollutant":"-","ct":"2019-12-13 15:03:29.781"},{"co":"0.5","so2":"9","o3":"49","no2":"29","aqi":"46","quality":"优质","pm10":"43","pm2_5":"32","site_name":"渔阳路","o3_8h":"21","primary_pollutant":"-","ct":"2019-12-13 15:03:29.788"},{"co":"0.4","so2":"22","o3":"-","no2":"33","aqi":"38","quality":"优质","pm10":"38","pm2_5":"23","site_name":"雍阳西道","o3_8h":"40","primary_pollutant":"-","ct":"2019-12-13 15:03:29.795"},{"co":"0.7","so2":"6","o3":"62","no2":"9","aqi":"20","quality":"优质","pm10":"-","pm2_5":"-","site_name":"东环路","o3_8h":"25","primary_pollutant":"-","ct":"2019-12-13 15:03:29.800"}]}
                }

ibcadmin 发表于 2020-6-1 09:14:21

将json转换成对象   用对象获取

FocusOn 发表于 2020-6-1 11:08:44

ibcadmin 发表于 2020-6-1 09:14
将json转换成对象   用对象获取

已经解决了,谢谢
页: [1]
查看完整版本: json数据解析