[英]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,你可以查看restTemplate , cxf或其他库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.