Value of type java.lang.String cannot be converted to JSONObject

来源:互联网 发布:怎么更新淘宝网新版本 编辑:程序博客网 时间:2024/05/17 02:49

解析jso报Value  of type java.lang.String cannot be converted to JSONObject。检查格式无错误。引起原因是由于utf-8的编码BOM头引起

/** * 4.0以下系统处理掉返回json的BOM头 *  * @param jsonStr * @return */public static String getJson(String jsonStr) {if (jsonStr != null && jsonStr.startsWith("\ufeff")) {LogUtil.d(tag, "jsonstr.exist(utf-8.BOM),json="+jsonStr, BaseAppCommon.Isdebug);// jsonStr = jsonStr.substring(1);jsonStr = jsonStr.substring(jsonStr.indexOf("{"),jsonStr.lastIndexOf("}") + 1);}return jsonStr;}

4.0以上已有包含处理的代码。