用gson加载JSON

尝试加载JSON文件时出现错误,但这是什么意思?

   public class Collection{
        private List<Book> books;
        private Book book;



            public static Collection loadFromJSONFile (File file){
                Gson gson = new Gson();
                JsonReader jsonReader = null;
                try {
                    jsonReader = new JsonReader(new FileReader(file));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                    System.out.println("Error");
                }
                return gson.fromJson(jsonReader,  Collection.class);
            }

预期为BEGIN_OBJECT,但在第1行第2列路径$处为BEGIN_ARRAY

JSON文件是

[
  {
    "title": "Thinking in Java (4th ed.)",
    "authorName": "Eckel, Bruce",
    "yearReleased": 2006,
    "bookGenre": "NON_FICTION"
  },
  {
    "title": "The Ultimate Hitchhiker\u0027s Guide to the Galaxy",
    "authorName": "Adams, Douglas",
    "yearReleased": 1979,
    "bookGenre": "FICTION_COMEDY"
  },
  {
    "title": "The Hobbit",
    "authorName": "Tolkien, J.R.R.",
    "yearReleased": 1937,
    "bookGenre": "FICTION_FANTASY"
  }
]
评论