org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
来源:互联网 发布:手机自动应答软件 编辑:程序博客网 时间:2024/05/17 01:35
解析服务器返回的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自带的编辑器引入的。】
转自:http://blog.csdn.net/forlong401/article/details/18256269
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
- VC运行库相关地址
- thinkphp配置nginx伪静态并解决PATHINFO问题和fix_pathinfo漏洞
- iptables配置允许vpnserver(softether vpn)
- MYSQL存储过程:批量更新数据
- MYSQL存储过程:批量更新数据2(产品品牌)
- org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
- 让阿里云支持ipv6(其他多数VPS通用)
- LeetCode 28. Implement strStr()
- 柬埔寨手机上网资费套餐(3G/4G上网)
- JavaScript 变量 的一些认识
- snmp switch traffic交换机带宽
- CentOS7安装mysql5.7.11
- 结合MongoDB开发LBS应用
- J2SE——Java编码