0
我試圖從json文件中讀取劇集列表(http://epguides.frecar.no/show/bigbangtheory/),計算劇集標題並在控制檯中打印它們。然而,因爲我是新來的使用json,我甚至無法達到第一個標題,總是返回null。對正確的方向有一點幫助或一點小小的提示將不勝感激。如何從對象中提取多個json對象
JSONParser parser = new JSONParser();
try {
File tmpDir = new File("src/bigbangtheory.json");
boolean exists = tmpDir.exists();
if (exists==true) System.out.println("file exists");
else System.out.println("file doesn't exist");
Object obj = parser.parse(new FileReader("src/bigbangtheory.json"));
JSONObject season = (JSONObject) obj;
System.out.println(obj);
Object title = (Object) season.get("title");
System.out.println(title);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (org.json.simple.parser.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
使用傑克遜解析器。可能會更容易:) – MarianP