Android2.3解析Json出错
2017-10-13 16:01
387 查看
在android2.3上json出现此问题,提示错误“JSONException: Value of type java.lang.String cannot be converted to JSONObject”,而4.0上没问题。
部分错误log如下:
原因是服务器返回的数据UTF-8带有BOM头,含有BOM头的数据会多出来三个字节 efbbbf。
这样在解析json的时候就会有问题,android4.0对此已经做了处理,所以没有报错。
参考资料
JSONException: Value
of type java.lang.String cannot be converted to JSONObject
UTF-8文件的BOM头的来由及去除方法
Android 由于BOM头导致的Json解析出错
部分错误log如下:
12345 | 1 12-18 20:23:27.389: W/System.err(12927): org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject2 12-18 20:23:27.389: W/System.err(12927): at org.json.JSON.typeMismatch(JSON.java:107)3 12-18 20:23:27.389: W/System.err(12927): at org.json.JSONObject.<init>(JSONObject.java:158)4 12-18 20:23:27.389: W/System.err(12927): at org.json.JSONObject.<init>(JSONObject.java:171) |
这样在解析json的时候就会有问题,android4.0对此已经做了处理,所以没有报错。
12345678910111213 | //android 2.3public JSONTokener(String in) { this.in = in;}//android 4.0public JSONTokener(String in) { // consume an optional byte order mark (BOM) if it exists if (in != null && in.startsWith("\ufeff")) { in = in.substring(1); } this.in = in;} |
JSONException: Value
of type java.lang.String cannot be converted to JSONObject
UTF-8文件的BOM头的来由及去除方法
Android 由于BOM头导致的Json解析出错
相关文章推荐
- Android2.3解析json出错,4.0不报错
- Android2.3解析json出错,4.0不报错
- Android2.3解析json出错
- 如何处理Android2.3解析json出错,4.0不报错
- Android2.3解析json出错
- android 流解析成json出错
- 在Android2.3上运行app时出现json解析异常,而在4.0则没有
- Android fastjson多层嵌套解析出错解决方法
- Android 由于BOM头导致的Json解析出错
- android解析json出错原因Bom头
- android学习——由于BOM头导致的Json解析出错
- android_由于BOM头导致的Json解析出错
- FastJson将json解析成含有泛型对象,内部泛型对象再次解析出错的解决办法(Android)
- Ace教你一步一步做Android新闻客户端(三) JSON数据解析
- android使用Gson来解析json
- android Json解析全
- android Json解析详解(详细代码)
- Android中使用Gson解析JSON数据
- android json解析及简单例子
- Android 编程下使用 Google 的 Gson 解析 Json