JSONObject parse with gson
-
20-12-2019 - |
Question
I want to parse my JSONObject with gson. 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:
{
"Email": "",
"Id": 1,
"Picture": null,
"UserName": "User1"
}
Solution
Remove static
modifier from all variables and try it again.
Note: Make all variable private
and provide public
getter/setter
methods. learn more...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow