如何解决JSONArray 不带 String?
所以我目前正在尝试编写代码来读取 GET 请求的内容并将此请求转换为 JSON。
我目前正在尝试使用 JSON Simple 依赖项,但出于某种原因,JSONArray 不再接受字符串参数?
这是我目前的代码:
HttpGet get = new HttpGet(connection.getURL());
try {
HttpResponse response = client.execute(get);
if (response.getStatusLine().getStatusCode() == 200) {
httpentity entity = response.getEntity();
if (entity != null) {
StringWriter writer = new StringWriter();
IoUtils.copy(entity.getContent(),writer,StandardCharsets.UTF_8);
String json = writer.toString();
JSONArray jsonArray = new JSONArray(json); //This gives me an error expecting 0 arguments instead of one?
}
} else
Sierra.logger().log(new LogUtils.LogEntry("Couldn't update -> " + response.getStatusLine().getStatusCode() + " - " + response.getStatusLine().getReasonPhrase()));
} catch (IOException ex) { Sierra.logger().log(new LogUtils.LogEntry("Could not update,exception occurred while performing GET request to "
+ connection.getURL())); }
提前致谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。