I have a JSON file with 2 JSON-Arrays in it: One Array for routes and one Array for sights.
A route should consist of several sights where the user gets navigated to
Had the same problem for few days. Found a solution at last. The PHP server returned some unseen characters which you could not see in the LOG or in System.out.
So the solution was that i tried to substring my json String one by one and when i came to substring(3) the error went away.
BTW. i used UTF-8 encoding on both sides.
PHP side: header('Content-type=application/json; charset=utf-8');
JAVA side: BufferedReader reader = new BufferedReader(new InputStreamReader(is, "utf-8"), 8);
So try the solution one by one 1,2,3,4...! Hope it helps you guys!
try {
jObj = new JSONObject(json.substring(3));
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data [" + e.getMessage()+"] "+json);
}
if value of the Key is coming as String and you want to convert it to JSONObject,
First take your key.value into a String variable like
String data = yourResponse.yourKey;
then convert into JSONArray
JSONObject myObj=new JSONObject(data);