Json_异常_net.sf.json.JSONException: JSONObject["solution"] not found.

net.sf.json.JSONException: JSONObject["solution"] not found.

没有这个元素造成的。
  问题代码:

JSONObject json = smArr.getJSONObject(i);
json.getString("solution");

分析原因:

  json中没有这个key,更没有这个key所对应的值

解决办法:判断一下是否有这个key,没有就加入,并添加所对应的值""

    f (!json.has("solution")){
        json.put("solution", "");
    }
时间: 2024-08-29 16:58:48

Json_异常_net.sf.json.JSONException: JSONObject["solution"] not found.的相关文章

json解析异常 - net.sf.json.JSONException: java.lang.reflect.InvocationTargetException

注:在项目中, 我使用原生的ajax请求数据的时候, JSONObject没能帮我解析, 当却不给我报错, 我是在junit单元测试中测试的时候, 发现的.发现好多时候, 特别是通过ajax请求, 不给我们报错,很郁闷, 特别是ie, 有些问题, 得借助FireFox的返回结果分析. 当然, FireFox有时也没报错. 异常栈: net.sf.json.JSONException: java.lang.reflect.InvocationTargetException at net.sf.js

JSON中 net.sf.json.JSONException: java.lang.NoSuchMethodException异常

在json对象和java对象转换时 String s = "{'name':'name1','pwd':'pwd1'}"; Person p = (Person)JSONObject.toBean(JSONObject.fromObject(s), Person.class); System.out.println(p.getPwd()); 上面代码中出现以下异常: net.sf.json.JSONException: java.lang.NoSuchMethodException [

json数据转换异常:net.sf.json.JSONException: java.lang.reflect.InvocationTargetException

1 //存储Product对象的集合是从,Product是从mysql数据库中查询并添加的 2 ArrayList<Product> list = new ArrayList<Product>(); 3 4 //设置响应对象编码 5 response.setCharacterEncoding("utf-8"); 6 response.setContentType("text/html;charset=utf-8"); 7 8 //将list集

ajax请求json数据异常:nested exception is net.sf.json.JSONException: java.lang.reflect.InvocationTargetException] with root cause

ajax请求json数据异常:nested exception is net.sf.json.JSONException: java.lang.reflect.InvocationTargetException] with root cause 1.异常原因:所请求的json数据中包含java.util.date数据类型,但是在后台并没有将其格式转换 2.解决方法:添加工具类DateJsonValueProcessor import java.text.SimpleDateFormat; imp

net.sf.json.JSONException: There is a cycle in the

使用hibernate容易出现该问题,主要是由于pojo类属性存在级联关系.比如说员工和部门,在员工表里面有部门属性,而在部门表里面有个员工集合,这样就存在了嵌套引用的问题了,就会抛出这个异常. 解决方法很简单,在将每个对象转为json对象的时候用setExcludes函数将级联的属性去除掉就可以了,如下面: //得到所有部门     //返回json对象字符串     public String getAllDep(){         List list = deptDAO.findAll(

net.sf.json.JSONException: There is a cycle in the hierarchy!错误解决方案

原因分析:在解析bean时,出现死循环调用,即:多个Bean之间出现了相互调用解决办法:过滤去掉bean中引起死循环调用的属性: [java] view plain copy List<Project> projectList = projectServices.find();  //获取数据 //自定义JsonConfig用于过滤Hibernate配置文件所产生的递归数据 JsonConfig config = new JsonConfig(); config.setExcludes(new

net.sf.json.JSONException: &#39;object&#39; is an array. Use JSONArray instead

list集合转换JSON出错误 意思是:对象"是一个数组.使用jsonarray代替. 解决方法: 将JSONObject替换为JSONArray 代码: JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT); JSONArray json = JSONArray.fromObject(newList, jsonConfig);

net.sf.json.JSONException: &amp;#39;object&amp;#39; is an array. Use JSONArray instead

list集合转换JSON出错误 意思是:对象"是一个数组. 使用jsonarray取代. 解决方法: 将JSONObject替换为JSONArray 代码: JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT); JSONArray json = JSONArray.fromObject(newList, jsonConfig);

atitit.解决net.sf.json.JSONException There is a cycle in the hierarchy

atitit.解决net.sf.json.JSONException There is a cycle in the hierarchy 1. 环境:使用hibernate4跟个,,要不个哪的对象系列化成个json的时候儿有这个问题了... 1 2. 原因::hb默认的lazy 方式造成的当有关联对象的时候儿... 1 3. #---解决::lazy =false  (推荐).. 1 4. 别的有以下的四个方法可以解决hibernate的序列化问题 2 5. BeanUtils.copyProp