我正在尝试使用java从json文件中读取。到目前为止,这就是我所拥有的:
import jdk.nashorn.internal.parser.JSONParser;
import java.io.FileReader;
import java.util.Objects;
public static void main (String[] args){
JSONParser parser = new JSONParser(); //Error : JSONParser() in JSONParser cannot be applied to expected parameters ...
System.out.println("Reading JSON file ...");
FileReader fileReader = new FileReader("data.json"); // *file not found exception!
JSONObject json = (JSONObject) parser.parse(fileReader); //JSONParser cannot be applied to java.io.File.Reader
String t1 = (String) json.get("time");
System.out.println("Time: " + t1);
}我在本节中有以下错误:
Error:(14, 29) java: constructor JSONParser in class jdk.nashorn.internal.parser.JSONParser cannot be applied to given types;
required: java.lang.String,jdk.nashorn.internal.objects.Global,boolean
found: no arguments
reason: actual and formal argument lists differ in length我在目录中有文件data.json,但是它不能读取它并给我FileNotFoundException
我发现了以下几行:
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;这也给了我以下两个错误:
Error:(2, 23) java: package org.json.simple does not exist
Error:(3, 30) java: package org.json.simple.parser does not exist我正在使用IntelliJ IDEA 14.1.4。我如何解决这些错误?
发布于 2018-03-03 22:59:34
import jdk.nashorn.internal.parser.JSONParser这个解析器不是你要找的那个。本教程使用import org.json.simple.parser.JSONParser;,它要求通过将此依赖项添加到Maven项目中来添加适当的包:
<groupid>com.googlecode.json-simple</groupid>
<artifactid> json-simple</artifactid>
<version>1.1</version>或者通过在本教程中拥有正确的jar文件,json-Simpl-1.1.1.jar。
https://stackoverflow.com/questions/33321729
复制相似问题