2014-10-16 72 views
0

我想转换一个对象异常转换对象的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(); 
} 

有例外,我应该努力追赶?该代码工作正常几个小时前,所以我真的很难为了什么改变...

谢谢!

+0

不要日志显示未捕获的异常吗? – 2014-10-16 15:27:35

+0

只是“线程退出与未捕获的异常(组= 0x41d21d40)” – 2014-10-16 15:29:23

+0

“线程退出与未捕获的异常”必须有几个原因,发布您的所有LogCat消息或发布您的代码。 – Jorgesys 2014-10-16 15:29:26

回答

0

java.lang.ClassCastException:org.json.simple.JSONObject不能 投地org.json.JSONObject“我会考虑这样做......

好像你进口错了。parser.parse仿佛回到了另一种的JSONObject的

+0

是!正在使用“import org.json.JSONObject;”而不是“import org.json.simple.JSONObject;” – 2014-10-16 15:37:22

0

原来我是用

import org.json.JSONObject; 

,而不是

import org.json.simple.JSONObject