简体   繁体   English

用gson解析JSONObject

[英]JSONObject parse with gson

I want to parse my JSONObject with gson. 我想用gson解析我的JSONObject。 I write some code but doesn't work. 我写了一些代码,但是没有用。

public class User {
    @SerializedName("Email")
    public static String Email;
    @SerializedName("Id")
    public static int Id;
    @SerializedName("Picture")
    public static String Picture=null;
    @SerializedName("UserName")
    public static String UserName;
}

In my class: 在我的课上:

User result=new Gson().fromJson(response,User.class);

My JSONObject: 我的JSONObject:

{
    "Email": "",
    "Id": 1,
    "Picture": null,
    "UserName": "User1"
}

Remove static modifier from all variables and try it again. 从所有变量中删除static修饰符,然后重试。

Note: Make all variable private and provide public getter/setter methods. 注意:将所有变量设为private并提供public getter/setter方法。 learn more... 学到更多...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM