There is such a code to get the string value:
json = response.toString(); JsonObject statsObj = parser.parse(json).getAsJsonObject(); JsonElement stats = statsObj.get("status"); String status = stats.toString(); System.out.println(status); The status value is a string. When I try to get any other numeric value, I get a NullPointerException error:
response.toString(); JsonObject statsObj = parser.parse(json).getAsJsonObject(); JsonElement stats = statsObj.get("last_battle_time"); int lbt = stats.getAsInt(); System.out.println(lbt); Tell me how to change the parser code for numeric values?
JSON structure
{ "status": "ok", "meta": { "count": 1 }, "data": { "36791942": { "last_battle_time": 1435324597, "account_id": 36791942, "created_at": 1419093115, "updated_at": 1436952967, // ... другие поля... } } }
stats.getAs*()methods? - Nofate ♦stats.getAsInt(), thenstats == null, thenstatsObj.get("last_battle_time")returnednull. Show the value of thejsonvariable. - Nofate ♦