JSON ファイルを解析しようとしていますが、間違いがわかりません (小さな例は問題なく動作します)
ソング.json
{
"song": {
"fileInfo": {
"version": "0.1",
"createdIn": "PickWorks Studio",
"modifiedIn": "PickWorks Studio",
"modified": "2010-01-28T13:15:30+01:00"
},
"properties": {
"authors": [
{
"name": "Juri Traktori",
"type": "music",
"lang": "en"
}
],
"titles": [
{
"title": "Rainy day",
"lang": "en",
"original": true
},
{
"title": "Descowe dni",
"lang": "pl"
}
],
"copywright": "Michal Tomanek",
"released": "19-03-1993",
"transposition": -3,
"tempo": {
"type": "text/bpm",
"value": "moderate/90"
},
"key": "A",
"version": 0.99,
"publisher": "myself",
"keywords": [ "grace", "words","amazing"],
"verseOrder": "v1 v2 v1 v1 v2",
"themes": [
{
"theme": "adoration"
}
]
},
"lyrics": [
{
"section": "v1",
"lines": [
{
"lang": "en",
"part": "man",
"text": "How <chord name=\"A\"/>great is <br/>your love",
"comment": "Sing softly"
},
{
"lang": "en",
"part": "woman",
"text": "How great is your love to us"
}
]
}
]
}
}
SongType.java: (かなり長い) http://pastebin.com/uaEY7dty
いつものようにすると:
Gson gson = new Gson() ;
SongType parsed = gson.fromJson(json, SongType.class);
クラッシュします...数日間立ち往生していて、正しく動作しません。
ところで:SOに関する私の最初の質問なので、本来あるべき姿で提示されていない場合はすみません。
編集:
Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 692
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:176)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172)
at com.google.gson.Gson.fromJson(Gson.java:803)
at com.google.gson.Gson.fromJson(Gson.java:768)
at com.google.gson.Gson.fromJson(Gson.java:717)
at com.google.gson.Gson.fromJson(Gson.java:689)
at Main.main(Main.java:14)
Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 692
at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:374)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:165)
編集2:
1) 曲は静的になりました 2) 歌詞はリスト内にあります (内部にはさらにセクションがあります)
編集3:
import java.util.List;
public class SongType {
public static Song song;
public class Song {
public FileInfo fileInfo;
public Properties properties;
public List<Lyrics> lyrics;
public FileInfo getFileInfo() {return fileInfo;}
public Properties getProperties() {return properties;}
public List<Lyrics> getLyrics() {return lyrics;}
public void setFileInfo(FileInfo fileInfo) {this.fileInfo = fileInfo;}
public void setProperties(Properties properties) {this.properties = properties;}
public void setLyrics(List<Lyrics> lyrics) {this.lyrics = lyrics;}
}
//code continues here ...
しかし、それでもうまくいきません...他に何か不足していますか?