I’m trying to make a java class that will contain a response from a JSON that looks like this:
{
"Global Quote": {
"01. symbol": "IBM",
"02. open": "160.0000",
"03. high": "162.0400",
"04. low": "160.0000",
"05. price": "161.9600",
"06. volume": "4561342",
"07. latest trading day": "2023-12-08",
"08. previous close": "160.2200",
"09. change": "1.7400",
"10. change percent": "1.0860%"
}
}
So far i’ve tried using two seperate classes, one with a lot of String and double objects, and I landed on this most recently:
class VantageResponse { public Map<String, Object> globalQuote; }
I’ve been using google’s GSON.fromJson to parse the response into an object of class VantageResponse but it has always returned null. What am I doing wrong?
2
Answers
Start writing a class that has a global variable of hashmap and then call this method to where you are containing the response. So far I have understood this should work. You can comment on this answer for other answer.
It looks like you are on the right track, but there might be an issue with the structure of your VantageResponse class. Here’s a modified version that should work:
With this structure, you can use Gson to deserialize the JSON response: