What is the best way to convert a JSON code as this:
{
"data" :
{
"field1" : "value1",
"field2" : "value2"
}
}
in a Java Map in which one the keys are (field1, field2) and the values for those fields are (value1, value2).
Any ideas? Should I use Json-lib for that? Or better if I write my own parser?
Using the GSON library:
Use the following code:
With google's Gson 2.7 (probably earlier versions too, but I tested 2.7) it's as simple as:
Which returns a Map of type
class com.google.gson.internal.LinkedTreeMap
and works recursively on nested objects.