为什么我不能在 Java 中实例化 JSONObject(字符串无法转换为映射)



我正在阅读一篇 Stackoverflow 帖子(这里(,我正在编写答案中包含的代码,但我无法实例化 JSONObject。该帖子没有指定 JSONObject 的来源,因此导入如下:

  import org.json.simple.JSONObject;  
  String jsonData = response.body().string();
  JSONObject json = new JSONObject(jsonData); //jsonData marked as the soruce of the error and the message "incompatible types cannot convert string to map" shows.

你可能想要org.json.JSONObject .那个有一个接受字符串的构造函数。

最新更新