public class User { //省略其它 public String name; public int age; public String emailAddress; }
private void testGson() { Gson gson = new Gson(); String jsonString2 = "{\"name\":\"张三\",\"age\":24}"; User user = gson.fromJson(jsonString2, User.class); System.out.println("hello world:" + user.name); String jsonString = "{'header': {'alerts': [{'AlertID': '2', 'TSExpires': null, 'Target': '1', 'Text': 'woot', " + "'Type': '1'}, {'AlertID': '3', 'TSExpires': null, 'Target': '1', 'Text': 'woot', 'Type': '1'}], " + "'session': '0bc8d0835f93ac3ebbf11560b2c5be9a'}, 'result': '4be26bc400d3c'}"; Map map = gson.fromJson(jsonString, Map.class); System.out.println(map.getClass().toString()); System.out.println(map); }
标签:google,String,示例,System,public,json,User,gson,out From: https://www.cnblogs.com/bonelee/p/16597603.html