【问题标题】:org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]org.json.JSONException:JSONArray 文本必须以 '[' 在 1 [字符 2 第 1 行] 开头
【发布时间】:2017-06-06 07:18:13
【问题描述】:

当我想从本地地址 php 读取 JSON 数组时出现异常。 php 中的字符串如下所示:

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

我的加载代码如下所示:

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

除了:

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

【问题讨论】:

标签: java json


【解决方案1】:

你有一个例外,因为你的应用程序从不调用你的服务 url http://192.168.1.23/get_people.php。因此,当您使用new JSONArray("http://192.168.1.23/get_people.php") 时,应用程序会尝试使用字符串“http://192.168.1.23/get_people.php”创建一个 JSONArray,而不考虑您的 ws 的返回值。

一个WS的消费方式有很多种,可以看restTemplate、cxf或者其他库。

【讨论】:

  • 谢谢!我会去探索它,并尝试解决问题
猜你喜欢
  • 1970-01-01
  • 2017-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多