net.sf.json.JSONException: 'object' 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);

result = json.toString();

net.sf.json.JSONException: 'object' is an array. Use JSONArray instead

时间: 2024-08-06 07:49:49

net.sf.json.JSONException: 'object' is an array. Use JSONArray instead的相关文章

net.sf.json.JSONException: 'object' 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);

'object' is an array. Use JSONArray instead

错误是:对象是一个数组,使用JSONArray代替 错误代码为:JSONObject json=JSONObject.fromObject(usertypeList); 正确代码为:JSONArray json=JSONArray.fromObject(usertypeList); 注意:JSONObject只是单个java对象转化json对象 'object' is an array. Use JSONArray instead

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

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

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(

含有Date类型属性的实体类转化为JSONArray时报net.sf.json.JSONException: java.lang.reflect.InvocationTargetException

当我们通过session传递数据的时候我通常是: 直接在DAO里从数据库取出含Date类型的数据,而且通常不会将java.sql.Date转为java.util.Date. 这时候前台和后台都不会有任何问题,所以我们以为这样是正常的操作. 但是当我们用JSON传递数据的时候就会发现控制台会报一下错误信息: net.sf.json.JSONException: java.lang.reflect.InvocationTargetException 这时候我们可以再DAO里将java.sql.Dat

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集