【发布时间】:2019-05-03 14:23:41
【问题描述】:
考虑以下示例 Json 字符串:
{"Name":"val","FatherName":"val","MotherName":"val"}
我把上面的 Json 转换成下面的 pojo :
public class Info{
private String name;
private String father;
private String mother;
}
我想知道的是,当我执行以下操作时:
Gson.fromJson(jsonLine, Info.class);
json 对象中的键如何跟踪到我的 pojo 中的变量? FatherName中的键FatherName的值是如何存储在father中的Info.class中的?
【问题讨论】:
-
我怀疑这个 json + pojo 一起工作。刚刚检查:如果您将
toString添加到Info,输出将是“Info{name=null,father=null,mother=null}”,这是预期的,因为 Gson(如预期)无法在此处映射任何内容。