gpt4 book ai didi

java - "constructor JSONParser in class JSONParser cannot be applied to given types"发生错误

转载 作者:行者123 更新时间:2023-12-02 13:44:55 26 4
gpt4 key购买 nike

我正在尝试用 Java 语言和 Netbeans(作为 IDE)构建一个天气应用程序。代码如下:

URL link = new URL("http://api.dataweave.in/v1/weather/findByCity/?api_key=a93abfaea2a98410be0df095f72df25d7a5d5eb5&city=Shimla&date=20130501");
URLConnection uc1 = link.openConnection();
BufferedReader in1 = new BufferedReader(new InputStreamReader(uc1.getInputStream()));
StringBuilder weather = new StringBuilder();
weather.append(in1.readLine() + "\n");
String line="0";

while ((line = in1.readLine()) != null) {
weather.append(line + "\n");
}

String result=weather.toString();
JSONParser parser=new JSONParser();

JSONObject obj = (JSONObject)parser.parse(result);
JSONArray jarr = (JSONArray) obj.get("data");

System.out.println(((JSONObject) jarr.get(0)).get("city"));
System.out.println(((JSONObject) jarr.get(0)).get("country"));
System.out.println(((JSONObject) jarr.get(0)).get("min_today"));
System.out.println(((JSONObject) jarr.get(0)).get("max_today"));
System.out.println(((JSONObject) jarr.get(0)).get("desc_today"));
System.out.println(((JSONObject) jarr.get(0)).get("date"));

上线

JSONParser parser=new JSONParser();

JSONObject obj = (JSONObject)parser.parse(result);

我收到此错误:

constructor JSONParser in class JSONParser cannot be applied to given types
required: Source, Error Manager
found: No arguments
reason: actual and formal arguments list differs in length

我已经有“json-simple”jar 文件作为库。现在我该怎么办?

最佳答案

检查您的进口声明。您将从 jdk.nashorn 导入它。您尝试尝试的代码来自 org.json.simple.parser.JSONParser

关于java - "constructor JSONParser in class JSONParser cannot be applied to given types"发生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28629143/

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