我试图在我的安卓应用程序中获得解析Json字符串,但是我得到了下面的异常。请帮帮忙
异常:
org.json.JSONException: Value
{
"DateTime": "20 06 2014",
"Response": null,
"hoursLeft": 0,
"token": null,
"Error": null,
"IsTrialExpired": false
} 类型java.lang.String不能转换为JSONObject
码
JSONObject jsonObject = new JSONObject(s); // I get exception in this line
((EditText) findViewById(R.id.editTextSearch)).setText(jsonObject.getString("DateTime"));发布于 2014-06-24 12:11:40
谢谢各位的帮助:)
但我终于解决了上述问题。
问题在于我试图从服务器返回的字符串\"的格式。
无效字符串
"{\"Response\":\"6\/24\/2014 5:33:35 PM\",\"hoursLeft\":0,\"token\":\"\",\"Error\":\"\",\"IsTrialExpired\":false}"
有效字符串
{"DateTime":"24\/06\/2014","Error":"","IsTrialExpired":false,"Response":"","hoursLeft":0,"token":""}
在服务器端,我手动地将对象转换为json并返回它,这导致了问题。我只是在我的WCF操作合同中使用了ResponseFormat = WebMessageFormat.Json,它解决了这个问题。
https://stackoverflow.com/questions/24331582
复制相似问题