问题
{
"data.url" : "http://dev.com",
"value": [
{
"color": "red"
"shape": "rect"
},
{
"color": "blue"
"shape": "rect"
}
]
}
Tried using gson.json, but . character is blocking from creating class,
Is there a way to remap the dotted field?
回答1:
Because Java doesn't allow . in a variable name, you need to use the @SerializedName annotation on that field in your class:
public class MyPojo {
@SerializedName("data.url")
private String dataUrl;
...
}
来源:https://stackoverflow.com/questions/21274183/parse-json-using-gson-with-key-name-containing-period