以下集合如何存放到Map中:{ "licenseCode": "41gk58LQ26BLyyXWfJb7Pm/6BlEsYyu929on+jGytTuxALYy1AJrHDWs75r6pGU1", "collectors": [ //逆变器1 { //逆变器交流侧表计的网关编号 "sn": "col123456", "inverters": [ { //逆变器交流侧表计的仪表编号 "sn": "inv123456", //逆变器装机容量 "rated_power": "200", //逆变器交流侧表计的EPI "e_realtime": 1250, //逆变器交流侧表计的Ua "ac_uL1": 200, //逆变器交流侧表计的Ia "ac_iL1": 10, //逆变器交流侧表计的Ub "ac_uL2": 200, //逆变器交流侧表计的Ib "ac_iL2": 20, //逆变器交流侧表计的Uc "ac_uL3": 200, //逆变器交流侧表计的Ic "ac_iL3": 30, //逆变器交流侧表计的Fr "fac": 20, //逆变器交流侧表计的P "pac": 10 } ] }, //逆变器2 { "sn": "col123456", "inverters": [ { "sn": "inv123456", "rated_power": "200", "e_realtime": 1250, "ac_uL1": 200, "ac_iL1": 10, "ac_uL2": 200, "ac_iL2": 20, "ac_uL3": 200, "ac_iL3": 30, "fac": 20, "pac": 10 } ] } ] }
时间: 2023-07-03 22:04:01 浏览: 100
可以使用嵌套的Map来存放该集合,具体实现如下:
```java
Map<String, Object> map = new HashMap<>();
map.put("licenseCode", "41gk58LQ26BLyyXWfJb7Pm/6BlEsYyu929on+jGytTuxALYy1AJrHDWs75r6pGU1");
List<Map<String, Object>> collectors = new ArrayList<>();
Map<String, Object> collector1 = new HashMap<>();
collector1.put("sn", "col123456");
List<Map<String, Object>> inverters1 = new ArrayList<>();
Map<String, Object> inverter1 = new HashMap<>();
inverter1.put("sn", "inv123456");
inverter1.put("rated_power", "200");
inverter1.put("e_realtime", 1250);
inverter1.put("ac_uL1", 200);
inverter1.put("ac_iL1", 10);
inverter1.put("ac_uL2", 200);
inverter1.put("ac_iL2", 20);
inverter1.put("ac_uL3", 200);
inverter1.put("ac_iL3", 30);
inverter1.put("fac", 20);
inverter1.put("pac", 10);
inverters1.add(inverter1);
collector1.put("inverters", inverters1);
collectors.add(collector1);
Map<String, Object> collector2 = new HashMap<>();
collector2.put("sn", "col123456");
List<Map<String, Object>> inverters2 = new ArrayList<>();
Map<String, Object> inverter2 = new HashMap<>();
inverter2.put("sn", "inv123456");
inverter2.put("rated_power", "200");
inverter2.put("e_realtime", 1250);
inverter2.put("ac_uL1", 200);
inverter2.put("ac_iL1", 10);
inverter2.put("ac_uL2", 200);
inverter2.put("ac_iL2", 20);
inverter2.put("ac_uL3", 200);
inverter2.put("ac_iL3", 30);
inverter2.put("fac", 20);
inverter2.put("pac", 10);
inverters2.add(inverter2);
collector2.put("inverters", inverters2);
collectors.add(collector2);
map.put("collectors", collectors);
```
这样就可以将该集合存放到Map中,其中包含了嵌套的Map和List结构。
阅读全文