JSON Error: Error parsing data org.json.JSONException: A JSONArray text must start with '[' at character 1 of why?
I am getting the following error with andoroid trying to return data from PHP
Error: Error parsing data org.json.JSONException: A JSONArray text must start with '[' at character 1 of
PHP SCRIPT:
<?php
#
header('Conten开发者_开发百科t-type: application/json');
print json_encode(array('name' => 'john'));
#
?>
THE RETURN:
09-07 08:49:04.740: INFO/result(704): {"name":"john"}
please help me
Here in this code mention above( JSONArray jArray = new JSONArray(result);).result is not a JSONArray and so you need to convert the result into JsonArray by adding "["+result+"]" or you need to create JSONObject.
One answer JSONArray jArray = new JSONArray("["+result+"]");
other answer JSONObject jobject=new JSONObject(result);
Looks like you are trying to parse an object with the Array parser instead of the JSON object parser
精彩评论