google gson解析json示例

1
2
3
4
5
6
public class User {
    //省略其它
    public String name;
    public int age;
    public String emailAddress;
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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);
}

  

posted @   bonelee  阅读(38)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
历史上的今天:
2021-08-18 WhatWeb使用——可识别Web技术,包括内容管理系统(CMS),博客平台,统计/分析包,Javascript库,服务器和嵌入式设备
2021-08-18 nmap -A 启用操作系统和版本检测,脚本扫描和路由跟踪功能
2020-08-18 wireshark 导出tls ssl证书
点击右上角即可分享
微信分享提示