2013年10月23日 星期三

Android - 使用JSON的時候出現org.json.JSONException: Value  of type java.lang.String cannot be converted to..


參考:解决org.json.JSONException: Value  of type java.lang.String cannot be converted to JSONArray

問題:使用android的時候發現一個怪問題,當我使用new JSONObject(jsonstr)時會報exception:

org.json.JSONException: Value  of type java.lang.String cannot be converted to...

而且這個情況只有在2.x(沒實際每個版本測試過,估計是3.0以下都會)出錯,在4.1則正常

解答:因為在我使用的情況是,json字串為http回傳的內容,只要將這個輸出的html編碼改為UTF8 without BOM編碼格式即可.

(但是一般win的筆記本似乎無法更改BOM編碼,因此我是另外下載notepad++更改的,請見上述參考連結)

沒有留言:

張貼留言