我想把下面的 JSON 字符串转换成一个 java 对象:
String jsonString = "{
"libraryname": "My Library",
"mymusic": [
{
"Artist Name": "Aaron",
"Song Name": "Beautiful"
},
{
"Artist Name": "Britney",
"Song Name": "Oops I did It Again"
},
{
"Artist Name": "Britney",
"Song Name": "Stronger"
}
]
}"
我的目标是很容易地访问它,比如:
(e.g. MyJsonObject myobj = new MyJsonObject(jsonString)
myobj.mymusic[0].id would give me the ID, myobj.libraryname gives me "My Library").
我听说过 Jackson,但我不确定如何使用它来适应我的 json 字符串,因为它不仅仅是键值对,由于“ mymusic”列表涉及。如果杰克逊不是最佳人选,我怎么才能和杰克逊一起完成呢? 还是有更简单的方法?