生成如下报文用java实现,并且到最后new一个remap的map去接{ "personDatas": [ { "indexCodes": [ "c35f4a4e-8baa-4e88-b6e3-c4060135e7e6" ], "personDataType": "person" } ], "resourceInfos": [ { "resourceIndexCode": "0a869b06f4ff4da29949acf006405c39", "resourceType": "acsDevice", "channelNos": [ 1 ] } ], "startTime": "2018-09-03T17:30:08.000+08:00", "endTime": "2018-09-06T17:30:08.000+08:00" }
时间: 2023-07-05 13:29:40 浏览: 164
可以使用以下Java代码生成该报文并存储在 `remap` map 中:
```java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.gson.Gson;
public class Main {
public static void main(String[] args) {
// 构造personDatas
List<String> indexCodes = new ArrayList<>();
indexCodes.add("c35f4a4e-8baa-4e88-b6e3-c4060135e7e6");
PersonData personData = new PersonData(indexCodes, "person");
List<PersonData> personDatas = new ArrayList<>();
personDatas.add(personData);
// 构造resourceInfos
List<Integer> channelNos = new ArrayList<>();
channelNos.add(1);
ResourceInfo resourceInfo = new ResourceInfo("0a869b06f4ff4da29949acf006405c39", "acsDevice", channelNos);
List<ResourceInfo> resourceInfos = new ArrayList<>();
resourceInfos.add(resourceInfo);
// 构造整个报文
Report report = new Report(personDatas, resourceInfos, "2018-09-03T17:30:08.000+08:00", "2018-09-06T17:30:08.000+08:00");
// 转换为JSON格式
Gson gson = new Gson();
String json = gson.toJson(report);
System.out.println(json);
// 存储到remap中
Map<String, String> remap = new HashMap<>();
remap.put("report", json);
}
}
class Report {
private List<PersonData> personDatas;
private List<ResourceInfo> resourceInfos;
private String startTime;
private String endTime;
public Report(List<PersonData> personDatas, List<ResourceInfo> resourceInfos, String startTime, String endTime) {
this.personDatas = personDatas;
this.resourceInfos = resourceInfos;
this.startTime = startTime;
this.endTime = endTime;
}
}
class PersonData {
private List<String> indexCodes;
private String personDataType;
public PersonData(List<String> indexCodes, String personDataType) {
this.indexCodes = indexCodes;
this.personDataType = personDataType;
}
}
class ResourceInfo {
private String resourceIndexCode;
private String resourceType;
private List<Integer> channelNos;
public ResourceInfo(String resourceIndexCode, String resourceType, List<Integer> channelNos) {
this.resourceIndexCode = resourceIndexCode;
this.resourceType = resourceType;
this.channelNos = channelNos;
}
}
```
代码中将生成的JSON字符串存储在了 `remap` map 中,使用键值对的方式进行存储。根据需要,你也可以将JSON字符串存储到文件或其他数据存储方式中。
阅读全文