异常信息
Value of type java.lang.String cannot be converted to JSONObject
原因
json数据格式不正确,可使用在线验证工具进行验证
UTF-8 的BOM头导致。在 Android 2.2 至 2.3.3 中未作处理,Android 4.0 及以上已经在内部类中处理了。
// Android 4.0及以上
public 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;
}// Android 2.2至2.3.3
public JSONTokener(String in) {
this.in = in;
}
本文探讨了在Java环境中遇到的异常信息:无法将String类型转换为JSONObject的问题。主要原因是JSON数据格式错误或UTF-8 BOM头的存在。文章通过对比不同Android版本的处理方式,详细解释了如何解决该问题。
1817

被折叠的 条评论
为什么被折叠?



