【发布时间】:2020-05-04 17:51:21
【问题描述】:
我在 GET 中调用了一个 Rest API,我需要解析响应并获取一个键的值。 我正在使用:
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
这是我的代码:
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder sb = new StringBuilder();
while ((readLine = in.readLine()) != null) {
sb.append(readLine);
}
JSONObject jsonObject = new JSONObject(sb.toString());
jsonObject.get();
in.close();
但是在JSONObject jsonObject = new JSONObject(sb.toString()); 生成错误
错误:(32, 63) java: 不兼容的类型:java.lang.String 无法转换为 java.util.Map
非常感谢。
【问题讨论】:
标签: java json parsing json-simple rest