I need to parse a JSON Response that looks like:
{"key1": "value1",
"key2": "value2",
"key3":
{"childKey1": "childValue1",
"childKey2": "childValue2",
"childKey3": "childValue3" }
}
class Egg {
@SerializedName("key1")
private String mKey1;
@SerializedName("key2")
private String mKey2;
@SerializedName("key3")
// ???
}
I’m reading through the Gson docs but cannot figure out how to properly deserialize a dictionary to a Map.
Gson readily handles deserialization of a JSON object with name:value pairs into a Java
Map.Following is such an example using the JSON from the original question. (This example also demonstrates using a
FieldNamingStrategyto avoid specifying the serialized name for every field, provided that the field-to-element name mapping is consistent.)