android中的json解析的属性值,在android中解析我的json以获取特定值

这是我的JSON,我只想要下面的压力,最高温度,最低温度,湿度,温度。我如何解析它并获得以下值。在android中解析我的json以获取特定值

String finalJSON = buffer.toString();

JSONObject parentObject = new JSONObject(finalJSON);

JSONArray parentArray = parentObject.getJSONArray("weather");

List weathermodellist = new ArrayList<>();

for (int i = 1; i < parentArray.length(); i++) {

JSONObject finalObject = parentArray.getJSONObject(i);

WeatherModel weatherModel = new WeatherModel();

weatherModel.setTemp((float) finalObject.getDouble("temp"));

weatherModel.setHumidity((float) finalObject.getDouble("humidity"));

weatherModel.setTemp_max((float) finalObject.getDouble("temp_max"));

weatherModel.setTemp_min((float) finalObject.getDouble("temp_min"));

weatherModel.setPressure((float) finalObject.getDouble("pressure"));

weathermodellist.add(weatherModel);

}

return weathermodellist;

这是我的JSON:

{"coord":{"lon":77.22,"lat":28.67},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"base":"cmc stations","main":{"temp":300.3,"pressure":998,"humidity":88,"temp_min":299.82,"temp_max":301.15},"wind":{"speed":3.1,"deg":80},"clouds":{"all":90},"dt":1468499400,"sys":{"type":1,"id":7809,"message":0.0025,"country":"IN","sunrise":1468454578,"sunset":1468504257},"id":1273294,"name":"Delhi","cod":200}

+4

第一条;格式化你的代码,我正在嘲笑我的眼睛。第二;你甚至搜索过吗?这里有数百万个问题,文章和教程:http://stackoverflow.com/questions/9605913/how-to-parse-json-in-android –