我想将以下 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”列表。我如何与杰克逊一起完成此任务,或者如果杰克逊不是最适合此任务的人,我是否有更简单的方法可以完成此任务?