JAVA之带转义字符的json字符串解析

Json数据:

 

 
  1. {  
  2.     "ret": "0",  
  3.     "Weathers": "[{\"date\":\"2017-03-20\",\"weatherType\":\"阴,大部分地区有零星小雨或小雨,上午能见度2-5km转阴天间多云\",\"temperature_min\":\"6\",\"wind_force\":\"微风\",\"temperature_max\":\"12\",\"wind_direction\":\"\"},{\"date\":\"2017-03-21\",\"weatherType\":\"阴转多云\",\"temperature_min\":\"6\",\"wind_force\":\"微风\",\"temperature_max\":\"13\",\"wind_direction\":\"\"},{\"date\":\"2017-03-22\",\"weatherType\":\"多云转阴\",\"temperature_min\":\"6\",\"wind_force\":\"微风\",\"temperature_max\":\"14\",\"wind_direction\":\"\"},{\"date\":\"2017-03-23\",\"weatherType\":\"阴转小雨\",\"temperature_min\":\"3\",\"wind_force\":\"微风\",\"temperature_max\":\"10\",\"wind_direction\":\"\"},{\"date\":\"2017-03-24\",\"weatherType\":\"雨夹雪转多云\",\"temperature_min\":\"0\",\"wind_force\":\"微风\",\"temperature_max\":\"5\",\"wind_direction\":\"\"},{\"date\":\"2017-03-25\",\"weatherType\":\"多云转晴\",\"temperature_min\":\"5\",\"wind_force\":\"微风转3到4级\",\"temperature_max\":\"13\",\"wind_direction\":\"\"},{\"date\":\"2017-03-26\",\"weatherType\":\"晴\",\"temperature_min\":\"4\",\"wind_force\":\"3到4级\",\"temperature_max\":\"14\",\"wind_direction\":\"\"}]"  
  4. }  

 

 

 

 
    1. JSONObject jsonObject = new JSONObject(result);  
    2. String weathers = jsonObject.getString("Weathers");  
    3. JSONArray weathersArray = new JSONArray(weathers);  
    4. //直接这样解析会报错  
    5. //JSONArray weathersArray = jsonObject.getJSONArray("weathers");  

 

转载于:http://blog.csdn.net/panyzyw/article/details/64130020

 

posted @ 2018-01-01 12:06  Mr_伍先生  阅读(8286)  评论(0编辑  收藏  举报