简体   繁体   English

org.json.JSONException:JSONArray文本必须以'['at 1 [character 2 line 1]开头

[英]org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]

I have exception when I want to read JSON array from local address php. 当我想从本地地址php读取JSON数组时,我有异常。 String in php looks like this: php中的字符串如下所示:

[{"firstname":"ime1","lastname":"prezime1"},{"firstname":"ime2","lastname":"prezime2"},{"firstname":"ime3","lastname":"prezime3"}]

And my code for loading looks like this: 我的加载代码如下所示:

JSONArray jsonArray = new JSONArray("http://192.168.1.23/get_people.php");

Exceptoin is: Exceptoin是:

org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]

You have an exception because your application never calls your service url http://192.168.1.23/get_people.php . 您有一个例外,因为您的应用程序从不调用您的服务URL http://192.168.1.23/get_people.php So, when you use new JSONArray("http://192.168.1.23/get_people.php") , the application tries to create a JSONArray using the string " http://192.168.1.23/get_people.php ", and not considering the return value of your ws. 因此,当您使用new JSONArray("http://192.168.1.23/get_people.php") ,应用程序尝试使用字符串“ http://192.168.1.23/get_people.php ”创建JSONArray,而不考虑你的回归值。

There are many ways to consume a WS, you can look at restTemplate , cxf or other library. 有很多方法可以使用WS,你可以查看restTemplatecxf或其他库。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.json.JSONException:JSONArray文本必须以“ [”开头 - org.json.JSONException: A JSONArray text must start with '[' 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? org.json.JSONException: JSONObject 文本必须以 '{' at 1 [character 2 line 1] 开头 - org.json.JSONException: A JSONObject text must begin 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:JSONObject文本必须在字符1处以“ {”开头 - org.json.JSONException: A JSONObject text must begin with '{' at character 1 线程“ main” org.json.JSONException中的异常:JSONObject文本必须在1 [字符2行1]处以“ {”开头 - Exception in thread “main” org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1] org.json.JSONException:JSONArray [0]不是字符串 - org.json.JSONException: JSONArray[0] not a string org.json.JSONException:JSONObject [“地址”]不是JSONArray - org.json.JSONException: JSONObject[“address”] is not a JSONArray org.json.JSONException:找不到JSONArray [20] - org.json.JSONException: JSONArray[20] not found org.json.JSONException:JSONArray [0]不是JSONObject - org.json.JSONException: JSONArray[0] is not a JSONObject
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM