The API I'm working with return a number as a JSON header. Normally I'd just make a class from the header and use Gson to deserialize it, but I cant do that since the header is a number. Here an Api Sample
{"263": {"name": "George", "wage": 2000, "expenses": 1600}}
I tried to use the best Answer from this topic How to convert json objects with number as field key in Java? but I got this error
com.google.gson.stream.MalformedJsonException: Use
JsonReader.setLenient(true)
to accept malformed JSON at line 1 column 7 path $
Here is my code
public class checkapi {
int wage263;
int expenses263;
//getters and setters
public void set263() throws IOException, InterruptedException {
JsonParser parser = new JsonParser();
JsonObject obj = parser.parse("URL").getAsJsonObject();
Set<Entry<String,JsonElement>> set = obj.entrySet();
for (Entry<String,JsonElement> j : set) {
int wage = obj.get("wage").getAsInt();
int expenses = obj.get("expenses").getAsInt();
setWage263(wage);
setExpenses263(expenses);
}
}
}
Is there any way to fix this code or an alternative for it?