import org.apache.commons.io.FileUtils;
import org.json.JSONException;
import org.json.JSONObject;
public class ReadJSONSample {
public static void main(String[] args) throws IOException, JSONException {
File file = new File(ReadJSONSample.class.getResource("/wangxiaoer.json").toString());
String content = FileUtils.readFileToString(file);
JSONObject jsonObject = new JSONObject(content);
System.out.println("姓名是:"+jsonObject.getString("name"));
}
}
控制台运行后报错
Exception in thread "main" java.lang.NullPointerException
at json.ReadJSONSample.main(ReadJSONSample.java:13)