[英]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 我在尝试从PHP返回数据时遇到了与ororoid的以下错误
Error: Error parsing data org.json.JSONException: A JSONArray text must start with '[' at character 1 of 错误:解析数据org.json.JSONException异常:JSONArray文本必须以'['开头的字符1
PHP SCRIPT: PHP脚本:
<?php
#
header('Content-type: application/json');
print json_encode(array('name' => 'john'));
#
?>
THE RETURN: 回报:
09-07 08:49:04.740: INFO/result(704): {"name":"john"} 09-07 08:49:04.740:信息/结果(704):{“ name”:“ john”}
please help me 请帮我
看起来您正在尝试使用Array解析器而不是JSON对象解析器解析对象
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. 上面的这段代码中提到了(JSONArray jArray = new JSONArray(result);)。结果不是JSONArray,因此您需要通过添加“ [” + result +“]”将结果转换为JsonArray,或者需要创建JSONObject。
One answer JSONArray jArray = new JSONArray("["+result+"]"); 一个答案JSONArray jArray = new JSONArray(“ [” + result +“]”);
other answer JSONObject jobject=new JSONObject(result); 其他答案JSONObject jobject = new JSONObject(result);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.