0

このようなjsonファイルからデータを取得しようとします。

[
  {
    "type": "text",
    "content": "test test test",
    "time": 100
  },
  {
    "type": "text",
    "content": "abcedfg",
    "time": 100
  },
  {
    "type": "text",
    "content": "some data",
    "time": 100
  },
  {
    "type": "text",
    "content": "1234567",
    "time": 100
  }
]

そして、このようなクラスを定義しました。

class TextData {
    String type;
    String content;
    long time;

    TextData(String type, String content, long time) {
        this.type = type;
        this.content = content;
        this.time = time;
    }
}

ArrayDeque<TextData>このようにjsonデータを解析するためにGSONを使用しようとしました

    ArrayDeque<TextData> textDatas = 
            new Gson().fromJson(getJson(fileName), ArrayDeque.class);

メソッドgetJsonは json ファイルのデータを取得しますString

そして、それはうまくいきません。このエラーが発生します。

failed to deserialize json object "" given the type class java.util.ArrayDeque

どうすれば修正できますか?

4

1 に答える 1