有一次从服务器解析获取到的Json字符串突然报了这个异常,由于这个json是从 php页面上推送过来的,当时就查是不是由于编码问题引起的,所以就上网搜了,网上大部分都是说由于utf-8的bom头引起的,让去掉bom头,但是也 没解决了,即使在本地进行处理json字符串将bom头去掉,但是也不行。json字符串格式也没问题,所以可以肯定的是json字符内部有无法识别或者 未知的字符,所以当时就把当时得到的json字符串进行了如下处理:

String jsonStr = httpTools.doGet("URL接口地址",paramsBaseList);
String json = jsonStr.substring(jsonStr.indexOf("{"), jsonStr.lastIndexOf("}") + 1);

就很顺利的解决问题,也不报这个异常了,不解释,贴出来供大家参考。

转自:http://www.cnblogs.com/wang340/archive/2013/05/08/3066716.html

Json解析异常处理方式(JSONException: Value of type java.lang.String cannot be converted to JSONObject)的更多相关文章

  1. new JSONObject(str)无法解析 报错: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 解析服务器返回的Jso ...

  2. alue of type java.lang.String cannot be converted to JSONObject

    /** * 4.0以下系统处理掉返回json的BOM头 * * @param jsonStr * @return */ public static String getJson(String json ...

  3. 【spring boot】spring boot 前台GET请求,传递时间类型的字符串,后台无法解析,报错:Failed to convert from type [java.lang.String] to type [java.util.Date]

    spring boot 前台GET请求,传递时间类型的字符串,后台无法解析,报错:Failed to convert from type [java.lang.String] to type [jav ...

  4. 完美解决报错Failed to convert value of type 'java.lang.String' to required type 'java.util.Date'

    Failed to convert value of type 'java.lang.String' to required type 'java.util.Date' 首先这个错误的意思是 前台页面 ...

  5. Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'xxx': no matching editors or conversion strategy found

    今天在完成项目的时候遇到了下面的异常信息: 04-Aug-2014 15:49:27.894 SEVERE [http-apr-8080-exec-5] org.apache.catalina.cor ...

  6. spring mvc出现 Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'endtime'

    在使用spring mvc中,绑定页面传递时间字符串数据给Date类型是出错: Failed to convert property value of type [java.lang.String] ...

  7. The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files

    最近在做J2ME开发项目,配置环境一切OK,但是打开项目时某些文件提示: The type java.lang.String cannot be resolved. It is indirectly ...

  8. Java 异常 Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date'

    查询时发送给服务器的日期的字符串格式:yyyy-MM-dd HH:mm:ss 服务器接收到日期的字符串之后,向 MySQL 数据库发起查询时,因为没有指定日期时间格式,导致字符串数据不能正确地转换为日 ...

  9. 前台传参数时间类型不匹配:type 'java.lang.String' to required type 'java.util.Date' for property 'createDate'

    springMVC action接收参数: org.springframework.validation.BindException: org.springframework.validation.B ...

随机推荐

  1. bootstrop之模态框关闭

    1.js中操作$('#myModal5').map(function() {//用id选择器选中要关闭的模态框 $(this).modal('hide'); //关闭 }); 2.用button在模态 ...

  2. 第三题 有如下Student 对象,  private String name;       private int age;       private int score;   private String classNum;  其中,classNum&

    //Student package zuoye; public class Student { private String name; private int age; private int sc ...

  3. 自定义alert和confirm

    var common = {}; common.showAlert = function (msg) { var html = "<div id='dialog_alert' clas ...

  4. 通过httplib2 探索的学习的最佳方式

    在工作中需要对一个视频点播两百次,使其成为热门视频,才能对其p2p情况进行测试.虽然可以手动点播两百次,但是利用python发送200次post请求,能减少很多的工作量.该发送请求的方法用到了http ...

  5. 【转载】StringUtils方法介绍

    org.apache.commons.lang.StringUtils中方法的操作对象是java.lang.String类型的对象,是JDK提供 的String类型操作方法的补充,并且是null安全的 ...

  6. Vim 配置Markdown

    通过vundle工具安装以下插件: vim-markdown   语法高亮 vim-markdown-preview.vim  通过浏览器实时预览(支持同步滚动) -/.vimrc vundle部分添 ...

  7. 第十六节,基本数据类型,字典dict

    字典 常用操作: 索引 新增 删除 键.值.键值对 循环 长度 字典由键值对组成,由一个键(名称)和 一个值组成,与列表和元组不同的是里面的元素是有键的(名称) 所以当要打印字典时,打印字典变量加[键 ...

  8. 深入理解HTTP协议(转) 浏览器和服务器如何通信(HTTP协议)

    http协议学习系列 1. 基础概念篇 1.1 介绍 HTTP是Hyper Text Transfer Protocol(超文本传输协议)的缩写.它的发展是万维网协会(World Wide Web C ...

  9. 通过纯Java代码从excle中读取数据(为.xlsx文件)

    参考链接: 程序代码: package demo; import java.io.File; import java.io.IOException; import java.io.InputStrea ...

  10. apache:添加cgi模式

    最终期望:通过配置apache的cgi能够使得apache能通过cgi方式连接go程序(因为我们的后端程序是用go语言写的). 实验1: 期望:通过配置cgi使得应用程序能够跑起来. go代码: pa ...