json解析实例

例子:

/** 解析查询设备接口*/
String str = "{"+
"\"code\":0,"+
"\"message\":\"查询成功\","+
"\"count\":\"总记录数\","+
"\"courtInfo\":{"+
"\"courtId\":\"单位标识\","+
"\"courtName\":\"单位名称\","+
"\"trialRooms\":[{"+
"\"trialRoomId\":\"提讯室标识\","+
"\"trialRoomName\":\"提讯室名称\","+
"\"controFilePath\":\"控制文件下载路径\","+
"\"trialRoomType\":\"提讯室类型\","+
"\"trialRoomStatus\":\"提讯室状态\","+
"\"firm\":\"厂商代码\","+
"\"pcIp\":\"庭审主机电脑ip\","+
"\"macAddress\":\"庭审主机mac地址\","+
"\"printIp\":\"打印机IP\","+
"\"isNetPrint\":\"是否网络打印机\","+
"\"defaultDevice\":\"默认使用设备\","+
"\"interfaceId\":\"接口上报时的编号\","+
"\"devices\":{"+
"\"terminalDevices\":[{"+
"\"deviceName\":\"设备名称\","+
"\"deviceIp\":\"设备IP地址\","+
"\"deviceType\":\"设备型号\","+
"\"streamType\":\"流类型\","+
"\"cameraSignalName\":\"camera信号名称\","+
"\"isRecord\":\"是否需要录制\""+
"}],"+
"\"decodes\":[{"+
"\"deviceIp\":\"解码器设备IP地址\","+
"\"isDefault\":\"是否首选设备\","+
"\"channels\":[{"+
"\"channelNum\":\"解码器通道号\","+
"\"isDefault\":\"是否默认通道\""+
"}]"+
"}],"+
"\"encodes\":[{"+
"\"deviceIp\":\"设备ip\","+
"\"producer\":\"设备厂商\","+
"\"isDefault\":\"是否首选设备\","+
"\"channels\":[{"+
"\"channelNum\":\"通道号\","+
"\"signalName\":\"信号源名称\","+
"\"port\":\"输入端口\","+
"\"rtspURL\":\"RTSP访问URL\","+
"\"streamType\":\"拉流协议\","+
"\"partition\":\"画面分割模式\","+
"\"isDefault\":\"是否默认通道\""+
"}]"+
"}]"+
"}"+
"}]"+
"}"+
"}";
mLog1.info("str-->"+str);



/**下面进行解析*/
JSONObject sbobjetc = new JSONObject(str);
mLog1.info(sbobjetc.getString("code"));
mLog1.info("--->"+sbobjetc.getString("courtInfo"));
String sbcourtInfo = sbobjetc.getString("courtInfo");
JSONObject sbcourtInfoobj = new JSONObject(sbcourtInfo);
mLog1.info("courtId--->"+sbcourtInfoobj.getString("courtId"));
mLog1.info("trialRooms-->"+sbcourtInfoobj.getString("trialRooms"));
JSONArray sbjsonArray = sbcourtInfoobj.getJSONArray("trialRooms");
mLog1.info("jsonArray.lenth-->"+sbjsonArray.length());
for(int i=0;i<sbjsonArray.length();i++){
JSONObject strobjsb =new JSONObject();
strobjsb = sbjsonArray.getJSONObject(i);
mLog1.info("strobj---->"+strobjsb.getString("devices"));
JSONObject sbdevicesobj = new JSONObject(strobjsb.getString("devices"));
*//**下面的是取设备IP*//*
JSONArray sbterminalDevices = sbdevicesobj.getJSONArray("terminalDevices");
mLog1.info("sbterminalDevices.length()-->"+sbterminalDevices.length());
for(int ii=0;ii<sbterminalDevices.length();ii++){
JSONObject strobjsbterminal =new JSONObject();
strobjsbterminal = sbterminalDevices.getJSONObject(ii);
mLog1.info("strobj---->"+strobjsbterminal.getString("deviceIp"));
}
*//**下面的是取解码器IP*//*
JSONArray sbdecodes = sbdevicesobj.getJSONArray("decodes");
mLog1.info("sbdecodes()-->"+sbdecodes.length());
for(int ii=0;ii<sbdecodes.length();ii++){
JSONObject strobjsbsbdecodes =new JSONObject();
strobjsbsbdecodes = sbdecodes.getJSONObject(ii);
mLog1.info("strobjsbsbdecodes---->"+strobjsbsbdecodes.getString("deviceIp"));
}
*//**下面的是取编码通道集合*//*
JSONArray sbencodes = sbdevicesobj.getJSONArray("encodes");
mLog1.info("sbencodes()-->"+sbencodes.length());
for(int ii=0;ii<sbencodes.length();ii++){
JSONObject strobjencodes =new JSONObject();
strobjencodes = sbencodes.getJSONObject(ii);
mLog1.info("strobjencodes---->"+strobjencodes.getString("channels"));
// mLog1.info("strobjchannels---->"+strobjchannels.getString("rtspURL"));
*//**我要取直播流*//*
String srt = strobjencodes.getString("channels");
mLog1.info("srt---->"+srt);
//JSONObject sbchannelsobj = new JSONObject(srt);
JSONArray sbchannels = strobjencodes.getJSONArray("channels");
mLog1.info("sbencodes()-->"+sbchannels.length());
for(int iii=0;iii<sbchannels.length();iii++){
JSONObject strobjsbchannels =new JSONObject();
strobjsbchannels = sbchannels.getJSONObject(iii);
mLog1.info("strobjsbchannels---->"+strobjsbchannels.getString("rtspURL"));
mLog1.info("isDefault---->"+strobjsbchannels.getString("isDefault"));
}


}
}



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值