Изначально json приходит в виде (в списке items есть поле id равное 4 у первого элемента !!!):
{"response":{"count":2,"items":[{"id":4,"from_id":-183957790,"owner_id":-183957790,.....
Потом я достаю JSONObject response
JSONObject inputJSON = (JSONObject) JSONValue.parseWithException(resultJson);
JSONObject response = (JSONObject) inputJSON.get("response");
В итоге я получаю такой json (Поле id уже нету !!!):
{"count":2,"items":[{"date":1561831569,"from_id":-183957790,"comments":{"count":2,....
Как это можно исправить ? (Использую json-simple)
public static void main(String[] args) {
String json = "{\"response\":{\"count\":2,\"items\":[{\"id\":4,\"from_id\":-183957790,\"owner_id\":-183957790}]}}";
parseCurrentWeatherJson(json);
}
public static void parseCurrentWeatherJson(String resultJson) {
try {
JSONObject response = (JSONObject) ((JSONObject) JSONValue.parseWithException(resultJson)).get("response");
System.out.println(response);
JSONArray weatherArray = (JSONArray) response.get("items");
JSONObject weatherData = (JSONObject) weatherArray.get(0);
System.out.println(weatherData.keySet()); // you can see all objects keys
System.out.println(weatherData.get("owner_id"));//get value of 'owner_id' for example
} catch (org.json.simple.parser.ParseException e) {
e.printStackTrace();
}
}
Уже отвечал и еще раз отвечаю... Вот код, вот результат выполнения:
{"count":2,"items":[{"from_id":-183957790,"owner_id":-183957790,"id":4}]}
[from_id, owner_id, id]
-183957790
В первой строке последним светится айдишник.
Так что именно у Вас не получается?
Продвижение своими сайтами как стратегия роста и независимости