I'm trying to learn JSON parsing, and a quick question came up regarding how to parse JSON in which the "category" name can change based on the request from an external API (specifically a video game API I'm toying with).
As a random example, sending the API request with "laofuthetiger" as the URI returns JSON that looks like this:
{ "laofuthetiger": {
"id": 51044840,
"name": "Lao Fu the Tiger",
"profileIconId": 664,
"revisionDate": 1484537981000,
"summonerLevel": 30
}}
Changing the URI to "sloverlord" yields this:
{ "sloverlord": {
"id": 39943538,
"name": "sloverlord",
"profileIconId": 712,
"revisionDate": 1484537981000,
"summonerLevel": 30
}}
From my elementary understanding of JSON parsing using GSON, I'm able to gather data from the first JSON example by having a class that looks like this:
public class Player{
private SummonerDto laofuthetiger;
...
where SummonerDto contains the individual elements id, name, etc. However, I don't know how to handle the actual "category" (or however it's called) changing between API calls. With this solution, a call using laofuthetiger works but sloverlord would return an internal error for obvious reasons.
EDIT: For a bit more information, the URI looks something like this: dev.host.com/get_player_by_name/laofuthetiger?api_key=XXXXX
where "laofuthetiger" can be any player name.