org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
来源:互联网 发布:java怎么解决高并发 编辑:程序博客网 时间:2024/04/28 17:31
解析服务器返回的Json串时,JSONObject对象抛出了这个异常。
原以为是返回的json格式错误了,仔细对比看不出所以然。至少字符上看是格式没问题的。。
那就可能是编码的问题了。仔细比较每个字符,的确在json串头部发现字符:"\ufeff" 。
客户端解决方案:
public static final String removeBOM(String data) {
if (TextUtils.isEmpty(data)) {
return data;
}
if (data.startsWith("\ufeff")) {
return data.substring(1);
} else {
return data;
}
}
服务器端解决方案:
将输出此json的php源码重新用editplus之类用utf-8无BOM的编码保存。【不要用windows系统自带的记事本编辑php源码,这个BOM就是记事本这些windows自带的编辑器引入的。】
0 0
- org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
- org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
- org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
- org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
- org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
- org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
- org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
- org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
- org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
- org.json.JSONException: Value ok of type java.lang.String cannot be converted to JSONObject:
- org.json.JSONException: Value ok of type java.lang.String cannot be converted to JSONObject: [Caugh
- org.json.JSONException: Value of type java.lang.String cannot be converted to JSON
- org.json.JSONException: Value of type java.lang.String cannot be converted to JSON
- org.json.JSONException: Value of type java.lang.String cannot be converted to JSONArra
- JSONException: Value of type java.lang.String cannot be converted to JSONObject
- Json解析异常处理方式(JSONException: Value of type java.lang.String cannot be converted to JSONObject)
- Value of type java.lang.String cannot be converted to JSONObject
- Value of type java.lang.String cannot be converted to JSONObject
- Light OJ 1080 - Binary Simulation
- 第九课:Activity 及其子类的使用三:PreferenceActivity
- Android记住密码后自动登录
- eclipse导入项目之后出现红色叹号的解决办法
- C语言里sscanf函数的正则表达式
- org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
- JSTL <fmt>Date、Number格式化显示
- hd 1048 The Hardest Problem Ever
- 安卓开发:弹出自定义对话框自动播放视频(仿视频广告效果,使用mediaplayer和surfaceview做播放器)
- SQL join连接
- java设计模式之代理模式(8)
- 云计算技术解析 Amazon EC2 的幕后
- boost
- 【6 Weeks。一个肚子两个大。】