我正在尝试在 android 中解析 JSON,但在访问对象的子子项时遇到了问题。我正在尝试从以下内容中提取增强内容,
{"augment-list": {
"time": "12:01",
"channel": "channel1",
"augment": [
{"id": "123", "name": "here", "x": "5", "y": "10", "orientation": "up", "content": "some stuff"},
{"id": "456", "name": "there", "x": "12", "y": "25", "orientation": "down", "content": "more stuff"},
{"id": "789", "name": "over there", "x": "1", "y": "2", "orientation": "left", "content": "and more"}
]
}}
我尝试通过获取名为 augment 或 augment[0] 的 augment-list 的 JSON 对象来访问 augments,但无法弄清楚如何访问其中的每个 augment。
最佳答案
如果没有详细说明问题出在哪里,我无法判断可能是什么问题。你有错误吗?你能发布一些代码吗?
你有这样的东西吗?
json.getJSONObject("augment-list").getJSONArray("augment").getJSONObject(0).getInt("id")
关于java - 在java中解析JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1541125/