Unable to evaluate the expression Method threw ‘net.sf.json.JSONException‘ exception.
json格式字符串含有null值,用JSONArray.fromObject转换为json数组时报错
—————————————————————————————————
问题出现
一天突然发现平时正常运行的平台出错了。测试时发现报错
Could not write JSON: null object; nested exception is com.fasterxml.jackson.databind.JsonMappingException: null object (through reference chain: java.util.HashMap["data"]->java.util.HashMap["list"]->net.sf.json.JSONArray[0]->net.sf.json.JSONObject["id"])
问题出在这个第三方api的返回内容
{"page": {"total": 3,"page": 0,"size": 10},"data": [{"id": null,"deviceSerial": "C95252223",...},{"id": null,"deviceSerial": "D43652769",...},...],"code": "200","msg": "操作成功!"
}
多了“id”字段且它的值为null(之前用这个api是没有这个字段的,所以一直没出错)。
解析不了,于是转换过程中就出错了。
//sr为上面的返回内容JSONObject json = JSONObject.fromObject(sr);if(Integer.parseInt(json.get("code").toString()) == 200 ){responseMap.put("list", JSONArray.fromObject(json.get("data")));//这里出错responseMap.put("page", JSONObject.fromObject(json.get("page")));return ResponseData.success(responseMap);}
问题解决
使用fastjson中的JSON.parseArray()
import com.alibaba.fastjson.JSON;//sr为返回内容
JSONObject json = JSONObject.fromObject(sr);if(Integer.parseInt(json.get("code").toString()) == 200 ){responseMap.put("list", JSON.parseArray(json.get("data").toString()));responseMap.put("page", JSONObject.fromObject(json.get("page")));return ResponseData.success(responseMap);
}
Unable to evaluate the expression Method threw ‘net.sf.json.JSONException‘ exception.相关推荐
- 提问:Unable to evaluate the expression. 被呼叫方拒绝接收呼叫。
页面结构如下: index.html,里有两个框架页面 <body style="width:100%;height: 100%;border:0;margin:0px; paddin ...
- Method threw ‘io.netty.util.IllegalReferenceCountException‘ exception.
在学习netty指南2时, 做netty开发http+xml的测试代码时,遇到如下错误: 客户端发送请求,服务端可以正常收到,但是服务端给客户端的response在客户端却接收不到, 将断点打到服务端 ...
- 解决 idea Method threw ‘java.lang.NoClassDefFoundError‘ exception. Cannot evaluate xxx toString 问题
问题: Method threw 'java.lang.NoClassDefFoundError' exception. Cannot evaluate com.tianque.datagroup.d ...
- Method threw ‘java.lang.NullPointerException‘ exception. Cannot evaluate com.sun.proxy.xxx
我在debug的时候发现会出现 Method threw 'java.lang.NullPointerException' exception. Cannot evaluate com.sun.pro ...
- Method threw 'java.lang.NullPointerException' exception. Cannot evaluate org.json.JSONObject.toSt...
异常: Method threw 'java.lang.NullPointerException' exception. Cannot evaluate org.json.JSONObject.toS ...
- 记坑Method threw ‘feign.RetryableException‘ exception.
做微服务开发已经有一段时间了,但原理理解和学习还真是仅限于皮毛.甚至连皮毛都谈不上....本次核心问题是跨服务调用不走网关 上图: 目标:使用@FeignClient进行跨服务远程调用 异常:Meth ...
- Isight unable to evaluate matlab commands的解决办法
这两天在利用Isight进行优化时遇到一个问题,困扰了我很久.用到了matlab模块,优化简单的matlab程序时可以直接运行,复杂的matlab程序就出现"Isight unable to ...
- chipseeker注释出现Error in (function (classes, fdef, mtable) : unable to find an inherited method fo
chipseeker注释出现Error in (function (classes, fdef, mtable) : unable to find an inherited method for fu ...
- Debezium报错处理系列之三十六:Task threw an uncaught and unrecoverable exception. Task is being killed and will
Debezium报错处理系列之三十六:Task threw an uncaught and unrecoverable exception. Task is being killed and will ...
最新文章
- 6-6.用HLSL定义点光源
- 制药行业SAP项目里的那些MES系统
- IIS与COM组件权限的问题
- 通讯线路物理层编码类型总结(NRZ,MLT-3,4B/5B,8B/10B,64B/66B...)
- QML提供的JavaScript主机环境
- 【C语言学习】国嵌21__指针基础
- html获取qq头像代码,jQuery在线获取QQ名称和头像
- IOS-状态栏的简单操作
- store下拉框同步_关于选择主下拉框后~后面的下拉框跟着同步一起变化的问题~~...
- 两车相撞的力怎么计算_两车都向中间并线时相撞 算谁的责任
- IOConsole Updater 报错解决办法
- 我晕,原来是这个问题!
- MFC在一个工程中启动其他工程的exe文件
- 疯狂讲义java_《疯狂Java讲义》 1-概述
- 小程序中如何使用vantUi库
- 编写php自动脚本,自己编写自动签到脚本
- android popup
- 大数据、java、python、区块链、人工智能发展前景
- jQuery源码解析(架构与依赖模块)第一章 理解架构
- 程序员如何预防大龄危机
热门文章
- C++入门02-变量与基本数据类型
- 平面设计师学python_设计师学习编程意义大吗?
- 12.QCustomPlot中数据选择机制
- 服务器 python cant open file_服的解释|服的意思|汉典“服”字的基本解释
- 数据结构c语言王海燕版课后答案,c语言程序设计实验指导(学生用).doc
- Windows Server 2012 中删除或弃用的功能
- IDEA中的Structure模块使用详解
- 【新手建站教学】如何使用成本更低的虚拟主机实现快速建站?手把手教你搭建一个属于自己的网站。
- springboot http post请求报401 403 404错误
- 学术报告系列(三) - 复杂海况无人艇虚实迁移学习方法