//这是restoken的值
{
"EasyDarwin": {
"Header": {
"CSeq": "1",
"Version": "v1",
"MessageType": "MSG_SC_SERVER_GET_CHANNELS_CONFIG_ACK",
"ErrorNum": "200",
"ErrorString": "Success OK"
},
"Body": {
"ChannelCount": 200,
"Channels": [
{
"Audio": 0,
"Cdn": "",
"CdnEnable": 0,
"Channel": 1,
"Enable": 1,
"IP": "",
"Name": "chinnel1",
"OnDemand": 0,
"Onvif": "",
"Password": "",
"Port": 0,
"Protocol": "RTSP",
"Record": 0,
"Reserve1": "0",
"Reserve2": "",
"Reserve3": "0",
"Reserve4": "0",
"Reserve5": "",
"Rtsp": "rtsp://dss/monitor/param?cameraid=1000113%247&substream=2",
"Rtsprecord": "",
"Transport": "TCP",
"UserName": ""
},
{
"Audio": 0,
"Cdn": "",
"CdnEnable": 0,
"Channel": 2,
"Enable": 1,
"IP": "",
"Name": "chinnel2",
"OnDemand": 0,
"Onvif": "",
"Password": "",
"Port": 0,
"Protocol": "RTSP",
"Record": 0,
"Reserve1": "0",
"Reserve2": "",
"Reserve3": "0",
"Reserve4": "0",
"Reserve5": "",
"Rtsp": "rtsp://dss/monitor/param?cameraid=1000113%246&substream=1",
"Rtsprecord": "",
"Transport": "TCP",
"UserName": ""
},
{
"Audio": 0,
"Cdn": "",
"CdnEnable": 0,
"Channel": 3,
"Enable": 1,
"IP": "",
"Name": "chinnel3",
"OnDemand": 0,
"Onvif": "",
"Password": "",
"Port": 0,
"Protocol": "RTSP",
"Record": 0,
"Reserve1": "0",
"Reserve2": "",
"Reserve3": "0",
"Reserve4": "0",
"Reserve5": "",
"Rtsp": "rtsp:///dss/monitor/param?cameraid=1000113%2410&substream=2",
"Rtsprecord": "",
"Transport": "UDP",
"UserName": ""
},
{
"Audio": 0,
"Cdn": "",
"CdnEnable": 0,
"Channel": 4,
"Enable": 1,
"IP": "",
"Name": "chinnel4",
"OnDemand": 0,
"Onvif": "",
"Password": "ubnt13572468",
"Port": 0,
"Protocol": "RTSP",
"Record": 0,
"Reserve1": "0",
"Reserve2": "",
"Reserve3": "0",
"Reserve4": "0",
"Reserve5": "",
"Rtsp": "rtsp://admin:ubnt13572468@02/Streaming/Channels/2?transportmode=unicast",
"Rtsprecord": "",
"Transport": "TCP",
"UserName": ""
},
{
"Audio": 0,
"Cdn": "",
"CdnEnable": 0,
"Channel": 5,
"Enable": 0,
"IP": "36.110.6.226",
"Name": "chinnel5",
"OnDemand": 1,
"Onvif": "",
"Password": "12345",
"Port": 11272,
"Protocol": "RTSP",
"Record": 0,
"Reserve1": "0",
"Reserve2": "",
"Reserve3": "0",
"Reserve4": "0",
"Reserve5": "",
"Rtsp": "rtsp://admin:12341272/h264/ch1/main/av_stream",
"Rtsprecord": "",
"Transport": "TCP",
"UserName": ""
},
{
"Audio": 0,
"Cdn": "",
"CdnEnable": 0,
"Channel": 6,
"Enable": 1,
"IP": "",
"Name": "chinnel6",
"OnDemand": 0,
"Onvif": "",
"Password": "",
"Port": 0,
"Protocol": "RTSP",
"Record": 0,
"Reserve1": "0",
"Reserve2": "",
"Reserve3": "0",
"Reserve4": "0",
"Reserve5": "",
"Rtsp": "rtsp://290/dss/monitor/param?cameraid=1000113%245&substream=2",
"Rtsprecord": "",
"Transport": "UDP",
"UserName": ""
},
]
}
}
}
String restoken = (String) map.get("data");
JSONObject jsonObject = JSONObject.parseObject(restoken);
//获取第一层
JSONObject A1 = jsonObject.getJSONObject("EasyDarwin");
//获取第二层
JSONObject A2 = A1.getJSONObject("Body");
//获取第三层
List<Object> Array = A2.getJSONArray("Channels");
JSONArray jsonArray = new JSONArray(Array);
List<Integer> using = new ArrayList<Integer>();
//获取在用通道
for(int i = 0;i<jsonArray.size();i++) {
JSONObject jsonObject1 = jsonArray.getJSONObject(i);
using.add(jsonObject1.getInteger("Channel"));
System.out.println(jsonObject1.getInteger("Channel"));
}
json字符串转 对象
/*
* 交易正常的返回
* jsonStr = {“status”:200,“method”:“GET”,“requestTime”:“0.003”}
*/
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
ApiConsumer resultInfo = (ApiConsumer) JSONObject.toBean(jsonObject,ApiConsumer.class);
jsonArray转 对象List
String inventoryRes= "";//数据源
JSONArray a = JSONArray.parseArray(inventoryRes);
List<InventoryRes> inventoryResList = JSONArray.parseArray(a.toJSONString(),InventoryRes.class);
class ApiConsumer {
String status; // 返回状态
String method;// 请求方法
String requestTime;// 响应时间
}