• JSON数据转换



    1. 测试代码
    String goodsPrice = "{"appid":"1637474419867659","code":0,"msg":"","qid":"c167447f-78da-4db4-b886-623fecc45335"," +
                    ""result":true,"resultList":[{"region_code":"5010","barcode":"40"}],"sign":"22ACBF590295DC4D05017F69D382ADD6"," +
                    ""timestamp":1620371185,"version":"2.3"}";
    
    BaseResponse<StorePriceQueryResp> goods = JSON.parseObject(goodsPrice, new TypeReference<BaseResponse<StorePriceQueryResp>>() {
    });
    
    System.out.println(JSON.toJSON(goods));
    //TODO: {"msg":"","result":true,"resultList":[{"barcode":"40","region_code":"5010"}]}
    

    1. 泛型类
    @Data
    public class BaseResponse<T> {
    
        private String msg;
    
        private Boolean result;
    
        private List<T> resultList;
    
        private Integer total;
    }
    

    1. 实体类
    @Data
    public class StorePriceQueryResp {
    
        /**
         * ERP门店编码
         */
        private String region_code;
    
        /**
         * 商品条码
         */
        private String barcode;
    
        /**
         * ERP商品编码
         */
        private String item_code;
    
        /**
         * 牵牛花内码
         */
        private Long rid;
    
        /**
         * 当前售价
         */
        private String sale_price;
    
        /**
         * 市场价
         */
        private String reference_price;
    
        /**
         * 最近修改时间
         */
        private String timestamp;
    }
    

    1. 原数据
    {
        "appid": "1637474419867659",
        "code": 0,
        "msg": "",
        "qid": "c167447f-78da-4db4-b886-623fecc45335",
        "result": true,
        "resultList": [
            {
                "region_code": "5010",
                "barcode": "40"
            }
        ],
        "sign": "22ACBF590295DC4D05017F69D382ADD6",
        "timestamp": 1620371185,
        "version": "2.3"
    }
    

    1. 转换后数据
    {
        "msg": "",
        "result": true,
        "resultList": [
            {
                "barcode": "40",
                "region_code": "5010"
            }
        ]
    }
    
  • 相关阅读:
    android 打包错误
    mysql innoDB 挂了的临时解决方案
    android notification 传值关键
    maven eclipse 插件下载地址
    微信html5开发选哪一个
    android AsyncTask 只能在线程池里单个运行的问题
    关于Fragment 不响应onActivityResult的情况分析 (
    Android-BaseLine基础性开发框架
    linux网络流量实时监控工具之iptraf
    android 圆角按钮和按钮颜色
  • 原文地址:https://www.cnblogs.com/Twittery/p/14741364.html
Copyright © 2020-2023  润新知