org.json.JSONException: Value of type java.lang.String cannot be converted to JSON
2016-12-19 17:52
671 查看
我遇到这个错误的时候,网上有说是因为编码问题,还有的说是因为使用gson的时候创建的javabean有问题,后来我捣鼓了半天,发现我的是另一个问题:
当我报错的时候,log是这样的:
“{
“code”: 200,
“userId”: “006”,”token”:
“sF6iFzOhkPLU5UpLqCS5MGWfn3SQFkRvNUczICaWT2C1a+VYwp3lY7tvR0xFOBc0/ddO2GSj07w=”
}”
是因为我的json字符串两边多了两个双引号,应该修改成这样:
{
“code”: 200,
“userId”: “006”,”token”:
“sF6iFzOhkPLU5UpLqCS5MGWfn3SQFkRvNUczICaWT2C1a+VYwp3lY7tvR0xFOBc0/ddO2GSj07w=”
}
虽然解决的方式很简单,但是也是诱发异常的原因之一,记录一下,希望以后自己更加细心一点。
当我报错的时候,log是这样的:
“{
“code”: 200,
“userId”: “006”,”token”:
“sF6iFzOhkPLU5UpLqCS5MGWfn3SQFkRvNUczICaWT2C1a+VYwp3lY7tvR0xFOBc0/ddO2GSj07w=”
}”
是因为我的json字符串两边多了两个双引号,应该修改成这样:
{
“code”: 200,
“userId”: “006”,”token”:
“sF6iFzOhkPLU5UpLqCS5MGWfn3SQFkRvNUczICaWT2C1a+VYwp3lY7tvR0xFOBc0/ddO2GSj07w=”
}
虽然解决的方式很简单,但是也是诱发异常的原因之一,记录一下,希望以后自己更加细心一点。
相关文章推荐
- org.json.JSONException: Value ok of type java.lang.String cannot be converted to JSONObject: [Caugh
- 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 JSONArra
- org.json.JSONException: Value ok of type java.lang.String cannot be converted to JSONObject:
- org.json.JSONException: Value of type java.lang.String cannot be converted to JSONArra
- org.json.JSONException: Value of type java.lang.String cannot be converted to JSON
- Json解析异常处理方式(JSONException: Value of type java.lang.String cannot be converted to JSONObject)
- JSONException: Value of type java.lang.String cannot be converted to JSONObject
- Json解析异常处理方式(JSONException: Value of type java.lang.String cannot be converted to JSONObject)
- JSONException: Value of type java.lang.String cannot be converted to JSONObject
- Json解析异常处理方式(JSONException: Value of type java.lang.String cannot be converted to JSONObject)
- Value of type java.lang.String cannot be converted to JSONObject
- Value of type java.lang.String cannot be converted to JSONObject 异常
- org.json.JSONException: Value java.net.UnknownHostException of type java.lang.String cannot be conv
- Value of type java.lang.String cannot be converted to JSONObject
- java.lang.RuntimeException: Value <pre>bool(false) of type java.lang.String cannot be converted to J
- alue of type java.lang.String cannot be converted to JSONObject
- of type java.lang.String cannot be converted to JSONObject: Android
- Caused by: java.lang.ClassCastException: org.hibernate.type.StringType cannot be cast to org.hiberna
- Cannot assign value of type 'java.lang.String' to property 'file' of type 'org.apache.struts.upload.FormFile'