繁体   English   中英

将对象转换为JSONObject的异常

[英]Exception Converting Object to JSONObject

我正在尝试转换对象

Object jObj;
parser.parse(response);
jObj = parser.parse(response);

反应在哪里

{"as":false,"autoToggleOff":false,"autoToggleSeconds":0,"cs":false,"deviceId":"e4e4217f-eef2-4cd8-9a87-21264ddff836","deviceName":"Virtual Switch One","deviceType":1,"displayOrder":0,"et":null,"he":false,"il":false,"isControllerBacked":true,"lastLevelUpdate":"\/Date(1413470244538-0400)\/","level":99,"levelPresets":[],"name":"Virtual Switch One","newLevel":null,"newPowerState":null,"newPowerTimerSeconds":null,"nextEventPowerLevel":null,"nextEventPowerOn":null,"nextEventTime":null,"nodeId":0,"pd":true,"providerDeviceId":"141009173344","pushUpdates":false,"roomId":null,"shortId":2,"sr":null,"st":null,"visible":true}

从对象到JSONObject

JSONObject jsonObject;
jsonObject = (JSONObject) jObj;

我懂了

10-16 11:09:04.962: W/dalvikvm(14259): threadid=12: thread exiting with uncaught exception (group=0x41d21d40)

该代码被try / catch包围

} catch (JSONException e) {
    e.printStackTrace();    
} catch (ParseException e){
    e.printStackTrace();
}

我应该尝试捕获异常吗? 几个小时前代码运行良好,所以我真的很困惑发生了什么变化...

谢谢!

java.lang.ClassCastException:org.json.simple.JSONObject无法转换为org.json.JSONObject“我会研究一下...

好像您的进口是错误的。 parser.parse似乎返回了另一种jsonobject

原来我在用

import org.json.JSONObject;

代替

import org.json.simple.JSONObject

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM