【发布时间】:2020-02-06 13:10:42
【问题描述】:
我有地图列表并且地图包含 json 对象...我已经为每个具有相同服务名称的 json 对象创建了单独的列表,这意味着在下面的示例中,如果列表大小应该等于 serviceNameList 并且我想创建单独的列出来
表示理想的场景应该是
List<List<Map<String, String>>> lst =new ArrayList<ArrayList<Map<String, String>>>();
List<Map<String, String>> serviceInfoList = new ArrayList<Map<String, String>()
ArrayList<String> serviceNameList = new ArrayList<String>();
for (int i = 0; i < serviceInfoList.size(); i++) {
Map<String, String> serviceInfoMp = new HashMap<String, String>();
serviceInfoMp = serviceInfoList.get(i);
Set<Map.Entry<String, String>> serviceInfoSet = serviceInfoMp.entrySet();
for (Map.Entry<String, String> mapentry : serviceInfoSet) {
if (mapentry.getKey().equals("serviceName")) {
serviceNameList.add(mapentry.getValue());
}
}
}
地图包含 JSON 数据
表示为json下面的每个服务名称表单创建单独的列表并将其存储在列表中
{
"ServiceData": {
"ServiceInfo": [
{
"trav": "20200131T173017Z",
"real": "MyService",
"lintruntime": "7",
"upload": "184",
"build": "1717",
"buildproductruntime": "1709",
"EXITCODE": "0",
"totaltime": "3610"
},
{
"trav": "20200131T173017Z",
"real": "MyService",
"lintruntime": "7",
"upload": "184",
"build": "1717",
"buildproductruntime": "1709",
"EXITCODE": "0",
"totaltime": "3610"
},
{
"trav": "20200131T173024Z",
"real": "ERSampleService1",
"lintruntime": "38",
"upload": "381",
"build": "1765",
"buildproductruntime": "1767",
"EXITCODE": "0",
"totaltime": "3913"
}
]
}
}
表示从上面的 Json 我想要的列表大小为 2,因为两个服务名称 ERSampleService1 和“MyService”
这个列表应该包含覆盖 JSON 数据的地图列表。
基本上我想为每个服务信息创建列表..
我知道问题可能令人困惑
但我被困在这里......
谁知道怎么做
简而言之,创建地图列表并遍历它,
感谢任何帮助
【问题讨论】:
-
感谢分享。你有什么问题?
标签: java dictionary collections