I am trying to get parse Json
string in my android application but I am getting the below exception. 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
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. I just used the ResponseFormat = WebMessageFormat.Json
in my WCF operation contract and it solved the issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.