zoukankan      html  css  js  c++  java
  • 使用Gson解析含有集合的json数据

    json数据

    {
        "messageCode": "00000",
        "message": "统计停车场枪口空闲及总数量成功!",
        "data": [
            {
                "fastChargeLeisure": 0,
                "tatolFastCharge": 15,
                "slowChargeLeisure": 2,
                "tatolSlowCharge": 2,
                "carparkId": "1424"
            },
           {
                "fastChargeLeisure": 5,
                "tatolFastCharge": 17,
                "slowChargeLeisure": 4,
                "tatolSlowCharge": 3,
                "carparkId": "1425"
            }
        ]
    }
    
    
    Map map = gson.fromJson(json, Map.class);
    List<Map> data = (List<Map>)map.get("data");
    for(Map d:data) {
    double fastChargeLeisure = (double) d.get("fastChargeLeisure");
    double tatolFastCharge = (double) d.get("tatolFastCharge");
    double slowChargeLeisure = (double) d.get("slowChargeLeisure");
    double tatolSlowCharge = (double) d.get("tatolSlowCharge");
    long carparkId = Long.parseLong((String) d.get("carparkId"));
    carParkResults_List.forEach((carParkMobileResponseDTO) -> {
          if (carParkMobileResponseDTO.getCarParkId().equals(carparkId)){
                carParkMobileResponseDTO.setEvFreeLots((int)(fastChargeLeisure + slowChargeLeisure));
                carParkMobileResponseDTO.setEvTotalLots((int)(tatolFastCharge + tatolSlowCharge));
                }
          });
    }
    

    注意:使用gson.fromJson解析成map对象,其中Integer类型会默认转换为Double

  • 相关阅读:
    分布图
    针对回归训练卷积神经网络
    polyfit 多项式曲线拟合matlab
    Re-run failed tests in testng
    URI 和 URL的区别
    十分钟理解Gradle
    移动App测试实战—专项测试(转)
    adb 常用命令
    MySQL基本操作
    Java注解
  • 原文地址:https://www.cnblogs.com/xiaolaodi1999/p/14239218.html
Copyright © 2011-2022 走看看