使用gson解析JSON,其键名包含句点(.) [英] Parse JSON using gson with key name containing period (.)
本文介绍了使用gson解析JSON,其键名包含句点(.)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
{
"data.url" : "http://dev.com",
"value": [
{
"color": "red"
"shape": "rect"
},
{
"color": "blue"
"shape": "rect"
}
]
}
尝试使用gson.json,但是.
字符阻止了创建类,
有没有办法重新映射虚线字段?
Tried using gson.json, but .
character is blocking from creating class,
Is there a way to remap the dotted field?
推荐答案
由于Java不允许在变量名称中使用.
,因此您需要在类中的该字段上使用@SerializedName
批注:
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;
...
}
这篇关于使用gson解析JSON,其键名包含句点(.)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文