首页 > 其他分享 >google gson解析json示例

google gson解析json示例

时间:2022-08-18 09:33:28浏览次数:49  
标签:google String 示例 System public json User gson out

        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

相关文章