JAVA之带转义字符的json字符串解析
Json数据:
- {
- "ret": "0",
- "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\":\"\"}]"
- }
- JSONObject jsonObject = new JSONObject(result);
- String weathers = jsonObject.getString("Weathers");
- JSONArray weathersArray = new JSONArray(weathers);
- //直接这样解析会报错
- //JSONArray weathersArray = jsonObject.getJSONArray("weathers");
转载于:http://blog.csdn.net/panyzyw/article/details/64130020