简体   繁体   English

JSON错误:解析数据org.json.JSONException时出错:JSONArray文本必须在字符1处以'['开头,为什么?

[英]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.

相关问题 org.json.JSONException:JSONArray文本必须以&#39;[&#39;at 1 [character 2 line 1]开头 - org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1] 尝试解析 JSON 字符串时出错。 org.json.JSONException:JSONArray 文本必须以 '[' 开头 - Getting error when trying parse JSON string. org.json.JSONException: A JSONArray text must start with '[' org.json.JSONException:JSONArray文本必须以“ [”开头 - org.json.JSONException: A JSONArray text must start with '[' 解析数据org.json.JSONException时出错:输入的字符0的结尾 - Error parsing data org.json.JSONException: End of input at character 0 of 解析数据org.json.jsonexception在字符0处的输入结束时出错 - Error parsing data org.json.jsonexception end of input at character 0 解析数据org.json.JSONException时出错:输入的字符0的结尾 - Error parsing data org.json.JSONException: End of input at character 0 of 解析数据org.json.jsonexception在输入字符1的末尾时出错 - Error parsing data org.json.jsonexception end of input at character 1 of JSON解析器:解析数据org.json.JSONException时出错:类型org.json.JSONArray无法转换 - JSON Parser: Error parsing data org.json.JSONException: type org.json.JSONArray cannot be converted 解析数据org.json.JSONException时出错:类型java.lang.String的值无法转换为JSONArray - Error Parsing Data org.json.JSONException: Value of type java.lang.String cannot be converted to JSONArray 获取错误:解析数据 org.json.JSONException 时出错:无法将 org.json.JSONArray 类型的值转换为 JSONObject - getting error :Error parsing data org.json.JSONException: Value of type org.json.JSONArray cannot be converted to JSONObject
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM