JSONObject text must begin with '{' at character 1 of错误解决
2017-06-06 23:52
621 查看
问题描述
如下代码,读取本地文件,将文本内容使用org.json解析为jsonobject对象,结果一直(catch到)爆出如题错误。StringBuilder sb=new StringBuilder(); BufferedReader br=new BufferedReader(new FileReader("d:/total.json")); String s = null; while((s = br.readLine())!=null){//使用readLine方法,一次读一行 sb.append(s); } JSONObject jsonObject2=null; String string=sb.toString().replaceAll(" ", "").trim(); System.out.println(string); try { jsonObject2=new JSONObject(string); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }
解决方案
经查证,文本内容确实没有问题,print的字符串符合json语法(可以到http://www.bejson.com/ 在线检测),最后发现是文件保存的格式如BOM问题。本人多试了几次就好了!
相关文章推荐
- org.json.JSONException: A JSONObject text must begin with '{' at character 1 of {解决方法
- org.json.JSONException: A JSONObject text must begin with '{' at character 1 of {解决方法
- 关于json解析时异常org.json.JSONException: A JSONObject text must begin with '{' at character 1 of {的解决方法
- json解析时出现异常org.json.JSONException: A JSONObject text must begin with '{' at character 1 of {的解决方法
- json解析异常org.json.JSONException: A JSONObject text must begin with '{' at character 1 of {的解决方法
- A JSONObject text must begin with '{' at character 1 of 1
- 【Android开发日记】jsonObject = new JSONObject(info)报错 A JSONObject text must begin with '{' at character
- A JSONObject text must begin with '{' at 1 [character 2 line 1]
- XCode中互相包含引起的"property with 'retain(or strong)' attribute must be of object type"错误与解决
- Java中json数据问题.报错 A JSONObject text must begin with '{'
- AFNetworking 关于JSON text did not start with array or object and option to allow fragments not set 错误
- AFNetworking 关于JSON text did not start with array or object and option to allow fragments not set 错误
- 解决 s.dependency 'AFNetworking' 出现 Property with 'retain (or strong)' attribute must be of object typ
- Kettle解析JSON错误,We MUST have the same number of values for all paths,We can not find and data with path [$.
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosi
- 解决illegal to have multiple occurrences of contentType with different values错误
- 解决The method onClick(View) of type new View.OnClickListener(){} must override a superclass错误
- Operation is not valid due to the current state of object 错误解决
- A different object with the same identifier value was already associated with the session错误解决方法
- Android应用程序上传错误The package name of your apk may not begin with any of the following values:[com.android, com.google, android, co