Я пытаюсь проанализировать json данные в Netbeans, но получаю ошибку. Ошибка:
java.lang.ClassCastException: class org.json.simple.JSONObject cannot be cast to class
org.json.simple.JSONArray (org.json.simple.JSONObject and org.json.simple.JSONArray are in
unnamed module of loader 'app')
Мой код выглядит так:
JSONParser parser = new JSONParser();
try
{
Object object = parser.parse(new FileReader("currentWeather7.json"));
JSONObject jsonObject = (JSONObject)object;
JSONArray wez = (JSONArray)jsonObject.get("currently");
for (Iterator it = wez.iterator(); it.hasNext();) {
JSONObject current = (JSONObject) it.next();
lineWeather = "In your area, it is currently: " + current.get("summary") + "\n" +
"It is " + current.get("temperature") + " degrees outside with a humidity of " + current.get("humidity") + "%."
+ " The wind speed is " + current.get("windSpeed") + " miles per hour.";
}
}
catch(FileNotFoundException fe)
{
fe.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
return lineWeather;
Текст, который он должен вернуть:
In your area, it is currently: Clear.
It is 51.66 degrees outside with a humidity of .44%. The wind speed is 9.22 miles per hour.
Данные, которые я попытка разбора выглядит следующим образом:
{
"currently": {
"summary": "Clear",
"precipProbability": 0,
"visibility": 10,
"windGust": 9.22,
"precipIntensity": 0,
"icon": "clear-day",
"cloudCover": 0.15,
"windBearing": 26,
"apparentTemperature": 49.51,
"pressure": 1019.8,
"dewPoint": 30.2,
"ozone": 318.2,
"nearestStormBearing": 32,
"nearestStormDistance": 243,
"temperature": 51.66,
"humidity": 0.44,
"time": 1585668360,
"windSpeed": 9.22,
"uvIndex": 2
},
"offset": -7,
"timezone": "America/Phoenix",
"latitude": 34.856894,
"longitude": -111.788274
}
Пожалуйста, дайте мне знать, что мне нужно исправить. Спасибо!