I'm trying to parse JSON with GSON and I think I'm getting the hang of it. The problem I have is it seems to stop parsing after the object name.
public static void main(String[] args) throws Exception {
Gson gson=new Gson();
String json = "{\"k1\":\"v1\",\"k2\":\"v2\"}";
Map<String,String> map=new HashMap<String,String>();
map=(Map<String,String>) gson.fromJson(json, map.getClass());
System.out.println(map.keySet());
}
Works fine and outputs:
[k1, k2]
And I can use those keys to get the values fine which is what I want to do.
If I use the same code with this JSON Object from json.org
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}
The only output I get is
[glossary]
I feel like there is something obvious I'm missing, can someone please help point me in the right direction?
Thank you.
glossary) and one value for that key (the object containing all the other stuff).