【发布时间】:2020-03-15 10:27:44
【问题描述】:
我有一些包含自定义名称字段的 json,例如:
{
"user_id": 123,
"user_name": "John",
"field_with_custom_name_1": "value1",
"field_with_custom_name_2": "value2",
"field_with_custom_name_3": "value3"
}
为了描述这个 json,创建了下一个模型:
public class UserData {
@SerializedName("user_id")
private int userId;
@SerializedName("user_name")
private String userName;
private Map<String, String> customFields;
}
但是在序列化之后,我们得到了具有下一个结构的 json:
{
"user_id": 123,
"user_name": "John",
"customFields": {
"field_with_custom_name_1": "value1",
"field_with_custom_name_2": "value2",
"field_with_custom_name_3": "value3"
}
}
您能否建议如何忽略结果中的“customFields”级别?
【问题讨论】: