"constructor JSONParser in class JSONParser cannot be applied to given types" 发生错误
"constructor JSONParser in class JSONParser cannot be applied to given types" error occured
我正在尝试用 Java 语言和 Netbeans(As 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
移除 import jdk.nashorn.internal.parser.jsonparser;
添加 import org.json.simple.parser.JSONParser;
我正在尝试用 Java 语言和 Netbeans(As 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
移除 import jdk.nashorn.internal.parser.jsonparser;
添加 import org.json.simple.parser.JSONParser;