2014-10-16 80 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 
相關問題