I am trying to convert following json string to JSONObject in android. But it throws JSONException. I have been digging up my mind for past few hours. Please help.
JSON String :
parseExchangeRate({"query":
{"count":1,"created":"2012-09-07T18:49:32Z","lang":"en-US","results":
{"row":{"rate":"55.395","name":"USD to INR"}}}});
Exception:
Value <jsonobject>parseExchangeRate( of type java.lang.String cannot be converted to JSONObject
Code :
String result = convertStreamToString(instream);
Log.d(TAG, result); //this outputs the above stated string
JSONObject json = new JSONObject(result); // this line thows exception
Thanks in advance.
what is the JSON string? you state that it’s,
but that looks like a line of javascript code. JSON != javascript. it looks like your web service is passing back a JSONP response. that’s fine, but since you are not a javascript client, you need to parse out the actual JSON string from that response.