这是我的J-SON解析我不明白我在哪里弄错了。任何人请看代码并告诉我我做错了什么。我还提供了J-SON URL
private Weather extractFeatureFromJSON (String json_incoming){
Weather sendInformation = null ;
try {
JSONArray jsonArray = new JSONArray(json_incoming);
JSONObject jsonObject = jsonArray.getJSONObject(0);
long timeReceived = jsonObject.getLong("EpochTime");
String weatherStatusReceived = jsonObject.getString("WeatherText");
boolean DayOrNightReceived = jsonObject.getBoolean("IsDayTime");
JSONObject fetchTemperature = new JSONObject("Temperature");
JSONObject dive_deep_t = fetchTemperature.getJSONObject("Metric");
double tempReceived = dive_deep_t.getDouble("Value");
JSONObject fetch_RF_Temperature = new JSONObject("RealFeelTemperature");
JSONObject dive_deep_t1 = fetch_RF_Temperature.getJSONObject("Metric");
double RF_tempReceived = dive_deep_t1.getDouble("Value");
JSONObject fetch_wind = new JSONObject("Wind");
JSONObject fetch_wind_direction = fetch_wind.getJSONObject("Direction");
int directionDegreeReceived = fetch_wind_direction.getInt("Degrees");
String in_which_direction = fetch_wind_direction.getString("Localized");
JSONObject fetch_wind_speed = fetch_wind.getJSONObject("Speed");
JSONObject fetch_wind_speed_in_metrics = fetch_wind_speed.getJSONObject("Metric");
double speedReceived = fetch_wind_speed_in_metrics.getDouble("Value");
int i = Integer.parseInt(in_which_direction);
int directionAndInWhich = directionDegreeReceived + i;
return new Weather(tempReceived , RF_tempReceived , DayOrNightReceived , weatherStatusReceived ,timeReceived , speedReceived , directionAndInWhich);
} catch (JSONException e) {
e.printStackTrace();
}
return null ;
}
答案 0 :(得分:0)
您需要getJSONObject
jsonObject
而不是创建new JSONObject
要获取Temperature, RealFeelTemperature, Wind
对象,您需要使用
jsonObject.getJSONObject("Temperature");
jsonObject.getJSONObject("RealFeelTemperature");
jsonObject.getJSONObject("Wind");
不是新JSONObject
new JSONObject("Temperature");
new JSONObject("RealFeelTemperature");
new JSONObject("Wind");