【发布时间】:2021-12-17 12:44:06
【问题描述】:
使用的 JSON 字符串:
'{"Sensors":[{\"name\":\"BLRB50CM_A\",\"cameraId\":\"Cam10\",\"id\":1,\"resolution\":\"1280 x 720\",\"officeLocation\":\"Offshore Development Center\",\"tags\":\"Entrance Camera, Parking Lot\",\"isActive\":\"true\",\"hls\":\"https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8\",\"rtsp\":\"rtsp://10.66.102.66:32278/mystream/parking_lot\",\"type\":\"sensor\",\"inputs\":[],\"outputs\":[2]}]}'
java pojo 类:
public class ServiceFlowData {
public ArrayList<Sensor> sensors;
public ArrayList<Sensor> getSensors() {
return sensors;
}
public void setSensors(ArrayList<Sensor> sensors) {
this.sensors = sensors;
}
}
用于转换为 java 对象的代码
Gson gson = new Gson();
ServiceFlowData serviceFlowData = gson.fromJson(jsonString,ServiceFlowData.class);
System.out.println("serviceFlowData"+serviceFlowData.getSensors());
我将获取传感器设为空。
我在这里错过了什么..?
【问题讨论】:
-
你可以使用这个链接:stackoverflow.com/questions/55533093/…
-
类必须具有与您要映射的 JSON 中相同的变量,并且它们区分大小写!