[英]json string cannot be converted to JSONObject
I am trying to get parse Json
string in my android application but I am getting the below exception. 我正在尝试在我的android应用程序中解析Json
字符串,但出现以下异常。 Please help 请帮忙
Exception : 例外情况 :
org.json.JSONException: Value
{
"DateTime": "20 06 2014",
"Response": null,
"hoursLeft": 0,
"token": null,
"Error": null,
"IsTrialExpired": false
}
of type java.lang.String cannot be converted to JSONObject 类型java.lang.String的对象不能转换为JSONObject
Code : 代码 :
JSONObject jsonObject = new JSONObject(s); // I get exception in this line
((EditText) findViewById(R.id.editTextSearch)).setText(jsonObject.getString("DateTime"));
Thanks guys for all your help :) 谢谢大家的帮助:)
but I have solved the above issue finally. 但我终于解决了上述问题。
The problem was with the format of the string \\"
which I was trying to return from server. 问题出在我试图从服务器返回的字符串\\"
的格式。
Invalid string 无效的字串
"{\\"Response\\":\\"6\\/24\\/2014 5:33:35 PM\\",\\"hoursLeft\\":0,\\"token\\":\\"\\",\\"Error\\":\\"\\",\\"IsTrialExpired\\":false}"
Valid string 有效字符串
{"DateTime":"24\\/06\\/2014","Error":"","IsTrialExpired":false,"Response":"","hoursLeft":0,"token":""}
on the server side I was manually converting the object into json and returning it and this was causing the issue. 在服务器端,我手动将对象转换为json并返回了它,这导致了问题。 I just used the ResponseFormat = WebMessageFormat.Json
in my WCF operation contract and it solved the issue. 我只是在WCF操作合同中使用了ResponseFormat = WebMessageFormat.Json
,它解决了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.