【发布时间】:2018-07-28 11:00:11
【问题描述】:
我正在学习 parcing,但在尝试实现它时遇到了问题。 发现了很多类似的问题和更多的解决方案,但没有任何帮助我
那是我的 json
{
"firstName": "name",
"lastName": "last",
"resistances": {
"a1": 1,
"a2": 2,
"a3": 3,
"a4": 4
}
}
播放器类
class Player implements Serializable{
String firstName;
String lastName;
int[] resistances;
public Player(String firstName, String lastName, int[] resistances) {
this.firstName = firstName;
this.lastName = lastName;
this.resistances = resistances;
}
}
以及我如何尝试分配
Gson gson = new Gson();
Player player = gson.fromJson("test.json", Player.class);
求救
【问题讨论】:
-
第三个变量将是一个对象.. 阻力..
-
和最外层的json pbj必须有名字..
-
如果“resistances”是一个数组,它应该是:“resistances”: [ 1, 2, 3, 4 ] 所以错误消息是因为它正在查找字符串“a1”