假设我有json字串
{"userId":"1","userName":"Yasir"}
现在我有一个班级用户
class User{ int userId; String userName; //setters and getters }
现在如何将上述json字符串转换为用户类对象
试试这个:
Gson gson = new Gson(); String jsonInString = "{\"userId\":\"1\",\"userName\":\"Yasir\"}"; User user= gson.fromJson(jsonInString, User.class);