I want to deserialize the following json data https://mtgox.com/code/data/getDepth.php. I keep getting an error. Below is my code.
Gson gson = new Gson();
String json = readHTTPS(new URL("https://mtgox.com/code/data/getDepth.php"));
AskBids askBids = gson.fromJson(json, AskBids.class);
My AskBids class look like:
public class AskBids {
private String [] [] asks;
private String [] [] bids;
public AskBids(){}
}
The error is get is com.google.gson.JsonParseException: Expecting object found: “asks”
Any ideas? Thanks
The JSON linked in the original question contains over 2,800 JSON tokens, element names and values. Here is a small section of that example that maintains the exact same structure.
That said, I copy-pasted the deserialization code from the original question, using both the original JSON and the shorter version I pasted above, and the code ran without error as expected.
Based on the error message
Expecting object found: "asks", I suspect that thereadHTTPS(URL)method is not returning the correct result, in that it is not including the opening{of the JSON. If this is the problem, but for some reasonreadHTTPS(URL)cannot be fixed, you could always “fix” its output by just concatenating the missing character(s).