解析Json 出现——java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
来源:互联网 发布:看high类似软件 编辑:程序博客网 时间:2024/06/05 09:38
在后台写了一个调用百度api接口,将GPS坐标转换成百度坐标的方法,
获得返回的一个json串,
jsonStr = "{\"status\":0,\"result\":[{\"x\":123.98636285887,\"y\":42.457133104428},{\"x\":123.98739247735,\"y\":42.462356027015}]}";
用main方法测试解析这个json串
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
JSONObject jsonobj = JSONObject.fromObject(jsonStr);
JSONArray objs = jsonobj.getJSONArray("result");
String[] db = new String[4];
JSONObject jo = objs.optJSONObject(0);
String x = jo.getString("x");
String y = jo.getString("y");
db[0]=x;
db[1]=y;
JSONObject jo1 = objs.optJSONObject(1);
String x1 = jo1.getString("x");
String y1 = jo1.getString("y");
db[2]=x1;
db[3]=y1;
完全没有问题。
但是在Jfinal 框架下,用web,从页面点击进入Controller->调用这个转换方法,解析的过程中
在JSONObject jsonobj = JSONObject.fromObject(jsonStr); 处报错:
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
很遗憾,不知道问题是什么,
没办法为了赶工,就用了阿里巴巴的fastjson,运行没有问题
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONArray;
代码片段,
JSONObject jsonobj = JSONObject.parseObject(jsonStr);
JSONArray objs = jsonobj.getJSONArray("result");
String[] db = new String[4];
问题解决。
虽然有些遗憾未能找到原因。有时间再琢磨琢磨
- 解析Json 出现——java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
- java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
- java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
- java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
- java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
- java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
- java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
- java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
- java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
- java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
- java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
- java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
- java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
- Struts2框架入门案例时的异常——java.lang.RuntimeException- java.lang.reflect.InvocationTargetException
- struts2启动报java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
- struts2报java.lang.RuntimeException: java.lang.reflect.InvocationTargetException错
- 启动JBoss出现“java.lang.RuntimeException: java.lang.reflect.InvocationTargetException”解决
- java.lang.reflect.InvocationTargetException
- VS2010 常用快捷键
- HDU 5651 xiaoxin juju needs help 逆元
- HDU1695 GCD (欧拉函数+容斥原理)
- 程序员之路——一个老程序员对刚上大学的学弟学妹的忠告
- UVA11806-Cheerleaders(容斥原理+二进制)
- 解析Json 出现——java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
- HDU 2841 Visible Trees 数论+容斥原理
- UVA 10325 The Lottery( 容斥原理)
- iOS之一个超赞的视频直播、第三方库,直播看这个就够了,支持RTMP推流,美颜直播
- HDU 4334 Trouble (暴力)
- POJ 3904 Sky Code (容斥原理)
- Kubernetes& swarm对比
- Shell命令
- HDU 4059 容斥原理+快速幂+逆元