我在JSONObject中遇到编译错误:
构造函数JSONObject(String)未定义
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.Serializable;
import java.util.ArrayList;
public class ResultList implements Serializable
{
private ArrayList<JSONObject> parliaments;
public ResultList(ArrayList<JSONObject> data) {
this.parliaments = data;
}
public ArrayList<JSONObject> getParliaments() {
return this.parliaments;
}
}
虽然代码仅根据JSON文档
答案 0 :(得分:0)
BufferedReader br;
try {
br = new BufferedReader(new FileReader("json.json"));
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
line = br.readLine();
}
JSONObject jsonObj = new JSONObject(sb.toString());
System.out.println(jsonObj);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
如果找不到文件,您应该处理异常。 我认为这适合你。