gpt4 book ai didi

java - 如何在 Java 中解析 JSON

转载 作者:行者123 更新时间:2023-11-29 21:13:19 25 4
gpt4 key购买 nike

这是我的 Java 代码:

...
HttpResponse response = httpclient.execute(httppost);
HttpEntity responseEntity = response.getEntity();
JSONObject serverResponse = new JSONObject(EntityUtils.toString(responseEntity));
String error = serverResponse.getString("error");
text1.setText(error);
...

我无法解析 JSON。

JSON:

[{"error":"1"}]

谢谢!

最佳答案

您的 jsonObjectjsonArray

这样做

JSONArray jarray= new JSONArray(EntityUtils.toString(responseEntity));
String error=jarray.getJSONObject(0).getString("error");

关于java - 如何在 Java 中解析 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22118972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com