【发布时间】:2011-03-15 16:31:34
【问题描述】:
我正在尝试将我的 Json 加载到我的班级中
public User() {
this.fbId = 0;
this.email = "";
this.name = "";
this.thumb = "";
this.gender = "";
this.location = "";
this.relationship = null;
this.friends = new ArrayList();
}
{
users:{
user:{
name:'the name',
email:'some@email.com',
friends:{
user:{
name:'another name',
email:'this@email.com',
friends:{
user:{
name:'yet another name',
email:'another@email.com'
}
}
}
}
}
}
}
我正在努力让 GSON 使用以下代码将用户详细信息加载到上述 Java 对象中
User user = gson.fromJson(this.json, User.class);
【问题讨论】:
-
那是 XML,不是 JSON,伙计。 ...好的,您编辑了您的问题。向我们展示 JSON! 还有,那是构造函数,不是类。
-
抱歉,代码部分做了噩梦,哈哈
-
阅读stackoverflow.com/editing-help。这只是 Markdown。
-
对,我是他们之前从来没有遇到过这样的问题,哈哈,对不起,谢谢大家的快速回复,很抱歉给你带来麻烦
-
它的构造函数来自类的所有属性,认为将 Json 与示例中的类匹配可能会有所帮助:)