将jsonobj转换为jsonarray时出现JSONException

时间:2012-07-03 07:12:47

标签: java json jsonexception

我在使用JSONArray.fromObject(jsonObj)时遇到JSONException。我无法弄清楚这个例外背后的原因。有人可以提供一些关于为什么会出现此错误的输入吗?

 net.sf.json.JSONException: java.lang.reflect.InvocationTargetException
at net.sf.json.JSONObject._fromBean(JSONObject.java:987)
at net.sf.json.JSONObject.fromObject(JSONObject.java:168)
at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:265)
at net.sf.json.JSONObject._processValue(JSONObject.java:2808)
at net.sf.json.JSONObject.processValue(JSONObject.java:2874)
at net.sf.json.JSONObject.setInternal(JSONObject.java:2889)
at net.sf.json.JSONObject.setValue(JSONObject.java:1577)
at net.sf.json.JSONObject._fromMap(JSONObject.java:1340)
at net.sf.json.JSONObject.fromObject(JSONObject.java:159)
at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:265)
at net.sf.json.JSONArray._processValue(JSONArray.java:2514)
at net.sf.json.JSONArray.processValue(JSONArray.java:2539)
at net.sf.json.JSONArray.addValue(JSONArray.java:2526)
at net.sf.json.JSONArray._fromCollection(JSONArray.java:1057)
at net.sf.json.JSONArray.fromObject(JSONArray.java:123)
at net.sf.json.JSONArray.fromObject(JSONArray.java:105)
at net.sf.json.JSONArray$fromObject.call(Unknown Source)

代码如下:

RESTClient restClient = new RESTClient(uri)
        Map<String, String> args = new HashMap<String,String>();
        args.put("responseContentType","ContentType.JSON");
        response = restClient.get(args)
        Object jsonObj = response?.getData()
        JSONArray jsonResp = JSONArray.fromObject(jsonObj)

我从REST服务获得的响应如下:

[{"contract":"/api/v1/contracts/3","draw":"/api/v1/draws/5","drawName":null,"drawNumber":1,"id":5,"periodFrom":"2007-01-10","periodTo":"2007-02-10"}]

0 个答案:

没有答案