有一次从服务器解析获取到的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. setting up a IPSEC/L2TP vpn on CentOS 6 or Red Hat Enterprise Linux 6 or Scientific Linux

    This is a guide on setting up a IPSEC/L2TP vpn on CentOS 6 or Red Hat Enterprise Linux 6 or Scientif ...

  2. matlab mse函数

    mse是检验神经网络算法的误差分析; mse是平均平方误差性能函数,是网络性能函数.平方误差就是指误差的平方.

  3. javascript显式类型的转换

    显式类型转换目的:为了使代码变得清晰易读,而做显示类型的转换常使用的函数:Boolean(),String(),Number()或Object()如:Nunber(5) //5String(true) ...

  4. apicloud教程

    http://community.apicloud.com/bbs/forum.php?mod=viewthread&tid=15939

  5. Openlayer 3 的画线测量长度

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. js常用API 数据类型 基本类型,基本包装类型,引用类型 Object String Array Boolean Number Date Math

    数据类型 变量.作用域及内存 基础类型(primitive value):Undefined.Null.Boolean.Number和String.这些类型在内存中分别占用固定大小的空间,他们的值保存 ...

  7. HDU 5933/思维

    题目链接[http://acm.hdu.edu.cn/showproblem.php?pid=5933]; 题意: 给出n堆物品,问能不能分成K个数量相等的堆,如果能分,则最少次数是多少.分的规则为: ...

  8. Vagrant常用命令

    Vagrant常用命令 Vagrant的几个命令: vagrant box add 添加box的操作 vagrant init 初始化box的操作 vagrant up 启动虚拟机的操作 vagran ...

  9. WebDriver获取table的内容(通过动态获取Table单元格的TagName对其innerHTML值进行获取)

    import java.util.ArrayList;import java.util.Iterator;import java.util.LinkedHashMap;import java.util ...

  10. wordpress建站过程3——header.php

    header.php中包含了一个页面的页头,也就是其他页面中重复出现的部分,包括用户登陆/登陆后显示的文字,导航条,网页logo,有的还包括轮播图. 下面就简单的贴上一个文件吧. <!DOCTY ...