Monsmi1e 2017-01-21 07:02 采纳率: 0%
浏览 7395

try catch内层嵌套try catch时内层catch捕获到异常,然后需要执行操作

//通过传入需要的数据的key。去将key对应的value转换为jsonObject类型的数据;
//前提是返回的数据的key不能重复,不然只会得到最后一层key的value;
public JSONObject conventJsonObjectByKey(String key,JSONObject jsonObject){
JSONObject returnJsonObject=null;
boolean flag=false;
if(jsonObject!=null) {
for (Map.Entry entry : jsonObject.entrySet()) {
if (entry.getKey().equals(key)) {
System.out.println("key"+key);
flag = true;
if (entry.getValue() != null) {
try{
System.out.println("entry.getValue()"+entry.getValue());
returnJsonObject = JSON.parseObject(entry.getValue().toString());
}catch (ClassCastException e){
System.out.println("entry.getKey()"+entry.getKey());
System.out.println("entry.getValue()"+entry.getValue());
returnJsonObject.put(entry.getKey(),entry.getValue());
}
}
else {
returnJsonObject.put(entry.getKey(),"");
}
}
}
if (flag == false) {
for (Map.Entry entry : jsonObject.entrySet()) {
JSONObject valueJsonObject = null;
try {
valueJsonObject = JSON.parseObject(entry.getValue().toString());
System.out.println("value"+entry.getValue());
System.out.println("valueObject"+valueJsonObject);
conventJsonObjectByKey(key, valueJsonObject);
} catch (Exception e) {
System.out.println("err"+entry.getValue());
}
}
}
}
return returnJsonObject;
}

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-01-26 15:48
    关注

    不知道你说的是什么意思,两层嵌套try catch就是了。

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器