使用 org.json.simple 库,我如何遍历 JSONArray,处理其单个对象和单个对象内的数组?
我已经找到了如何为不同的 JSON 库执行此操作的答案,但在我的情况下,我需要使用 org.json.simple。
这是我需要处理的 JSONArray 的示例:
[
{
"versions":[
{
"rocket_version":"3.3.0.0",
"pluginVersion":"1.0.1.0",
"uploaded":1429350563,
"changelog":"<ul>\r\n\t<li>ADDED: anti-suicide.imune permission<\/li>\r\n<\/ul>",
"url":"https:\/\/dev.rocket.foundation\/wp-content\/uploads\/AntiSuicide3.zip"
},
{
"rocket_version":"3.3.0.0",
"pluginVersion":"1.0.0.2",
"uploaded":1429283276,
"changelog":"<ul>\r\n\t<li>FIXED: hopefully fixed the allocated memory (needs testing)<\/li>\r\n<\/ul>",
"url":"https:\/\/dev.rocket.foundation\/wp-content\/uploads\/AntiSuicide2.zip"
},
{
"rocket_version":"3.3.0.0",
"pluginVersion":"1.0.0.1",
"uploaded":1429196020,
"changelog":"<ul>\r\n\t<li>FIXED: small exception every time someone suicide.<\/li>\r\n<\/ul>",
"url":"https:\/\/dev.rocket.foundation\/wp-content\/uploads\/AntiSuicide1.zip"
},
{
"rocket_version":"3.3.0.0",
"pluginVersion":"1.0.0.0",
"uploaded":1428923374,
"changelog":"",
"url":"https:\/\/dev.rocket.foundation\/wp-content\/uploads\/AntiSuicide.zip"
}
],
"author":"ApokPT",
"name":"Anti-Suicide",
"id":910,
"development_stage":"Release",
"headline":"Anti-Suicide relocation",
"url":"https:\/\/dev.rocket.foundation\/?post_type=rplugin&p=910"
},
{
"versions":[
{
"rocket_version":"3.3.0.0",
"pluginVersion":"1.0.0.0",
"uploaded":1429113571,
"changelog":"Updated needed libraries",
"url":"https:\/\/dev.rocket.foundation\/wp-content\/uploads\/ZaupWhitelist_1.0.0.02.zip"
},
{
"rocket_version":"3.3.0.0",
"pluginVersion":"1.0.0.0",
"uploaded":1429047352,
"changelog":"First release",
"url":"https:\/\/dev.rocket.foundation\/wp-content\/uploads\/ZaupWhitelist_1.0.0.01.zip"
}
],
"author":"Zamirathe",
"name":"Zaup Mysql Whitelist",
"id":929,
"development_stage":"Release",
"headline":"Whitelist in Mysql",
"url":"https:\/\/dev.rocket.foundation\/?post_type=rplugin&p=929"
},
{
"versions":[
{
"rocket_version":"3.3.0.0",
"pluginVersion":"1.3.5.0",
"uploaded":1429284290,
"changelog":"<ul>\r\n\t<li>FIXED: Possible memory leak (needs testing);<\/li>\r\n\t<li>FIXED: Reactivated strip on give kit;<\/li>\r\n\t<li>ADDED: Cooldown check for permission givekit.onjoin.<kitname><\/li>\r\n<\/ul>",
"url":"https:\/\/dev.rocket.foundation\/wp-content\/uploads\/GiveKit27.zip"
},
{
"rocket_version":"3.3.0.0",
"pluginVersion":"1.3.4.0",
"uploaded":1429192200,
"changelog":"<ul>\r\n\t<li>ADDED: givekit.onjoin.<kit name> permission<\/li>\r\n<\/ul>",
"url":"https:\/\/dev.rocket.foundation\/wp-content\/uploads\/GiveKit26.zip"
}
],
"author":"ApokPT",
"name":"Give Kit",
"id":858,
"development_stage":"Release",
"headline":"Give a Kit to another player or yourself",
"url":"https:\/\/dev.rocket.foundation\/?post_type=rplugin&p=858"
}
]
整个数组中的每个单独对象都有一个版本数组和一个“id”属性。对于每个单独的对象,我需要:
- 获取 'id' 属性的值
- 遍历 'versions' 数组中的每个对象,并获取其属性的值,例如 'url'、'changelog'、'pluginVersion' 等。
对于每个版本数组中的每个对象,我只需要调用一个接受 id 属性和 url/changelog/pluginVersion 属性的方法。
如何使用 org.json.simple 库在 Java 中完成此任务?
注意:我需要使用 org.json.simple 库!