In my code, I am trying to access some json return from server. But I can't convert json return from server to JsonObject. Here is my code,
result = post.getHttpData(Constants.UrlDepartureCity);
catchLog(result);
JSONObject obj=new JSONObject(result);
I use my custom catchLog to print json return in log.
09-23 14:53:59.940: I/DepartureCityAsync(23313):
{"status":"1","departure_city":[
{"entity_id":"1","field_depature_city_tid":"1","entity_type":"node"},
{"entity_id":"8","field_depature_city_tid":"1","entity_type":"node"},
{"entity_id":"12","field_depature_city_tid":"1","entity_type":"node"},
{"entity_id":"5","field_depature_city_tid":"2","entity_type":"node"},
{"entity_id":"9","field_depature_city_tid":"2","entity_type":"node"},
{"entity_id":"17","field_depature_city_tid":"2","entity_type":"node"},
{"entity_id":"6","field_depature_city_tid":"3","entity_type":"node"},
{"entity_id":"7","field_depature_city_tid":"5","entity_type":"node"}]}
And I copy the result and validate that json return in http://jsonlint.com/. There is no error, syntax also correct. But When I try to convert it to JsonObject I got this error.
09-23 14:53:59.940: W/System.err(23313): org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
How can I solve this problem? Please. Thanks