[英]org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]
[英]JSON Error: Error parsing data org.json.JSONException: A JSONArray text must start with '[' at character 1 of why?
我在嘗試從PHP返回數據時遇到了與ororoid的以下錯誤
錯誤:解析數據org.json.JSONException異常:JSONArray文本必須以'['開頭的字符1
PHP腳本:
<?php
#
header('Content-type: application/json');
print json_encode(array('name' => 'john'));
#
?>
回報:
09-07 08:49:04.740:信息/結果(704):{“ name”:“ john”}
請幫我
看起來您正在嘗試使用Array解析器而不是JSON對象解析器解析對象
上面的這段代碼中提到了(JSONArray jArray = new JSONArray(result);)。結果不是JSONArray,因此您需要通過添加“ [” + result +“]”將結果轉換為JsonArray,或者需要創建JSONObject。
一個答案JSONArray jArray = new JSONArray(“ [” + result +“]”);
其他答案JSONObject jobject = new JSONObject(result);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.