0
我有以下的JSON和我想要解析陣列(汽車),解析JSON陣列錯誤「的JSONObject解決不了」
[
{
"name": "John",
"city": "Berlin",
"cars": [
"audi",
"bmw"
],
當我用下面的代碼試過我有錯誤
JSONParser parser = new JSONParser();
JSONArray a = (JSONArray) parser.parse(new FileReader(
"C:\\General\\Json\\json.txt"));
for (Object o : a) {
JSONObject person = (JSONObject) o;
String name = (String) person.get("name");
System.out.println(name);
String city = (String) person.get("city");
System.out.println(city);
String job = (String) person.get("job");
System.out.println(job);
}
這裏是錯誤「jsonObject無法解析」 我應該如何克服它?
JSONArray cars = (JSONArray) jsonObject.get("cars");