次のJSONファイルを読み込もうとしています:
{ "rss" : {
"@attributes" : {"version" : "2.0" },
"channel" : {
"description" : "Channel Description",
"image" : {
"link" : "imglink",
"title" : "imgtitle",
"url" : "imgurl"
},
"item" : {
"dc_format" : "text",
"dc_identifier" : "link",
"dc_language" : "en-gb",
"description" : "Description Here",
"guid" : "link2",
"link" : "link3",
"pubDate" : "today",
"title" : "Title Here"
},
"link" : "channel link",
"title" : "channel title"
}
}
}
このオブジェクトに:
public class RSSWrapper{
public RSS rss;
public class RSS{
public Channel channel;
}
public class Channel{
public List<Item> item;
}
public class Item{
String description;//Main Content
String dc_identifier;//Link
String pubDate;
String title;
}
}
「アイテム」オブジェクトの内容を知りたいだけなので、呼び出し時に上記のクラスが機能すると想定しました。
Gson gson = new Gson();
RSSWrapper wrapper = gson.fromJson(JSON_STRING, RSSWrapper.class);
しかし、エラーが発生します:
スレッド「メイン」での例外 com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: BEGIN_ARRAY が必要でしたが、BEGIN_OBJECT でした
これが何を意味するのかよくわからないので、どこでエラーを探すべきかわかりません.GSONの知識が豊富な人が助けてくれることを願っています.
ありがとう :)