在java中解析JSON
Posted
技术标签:
【中文标题】在java中解析JSON【英文标题】:Parsing JSON in java 【发布时间】:2010-12-05 04:42:25 【问题描述】:我正在尝试在 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] 的增强列表的 JSON 对象来访问增强,但无法弄清楚如何访问内部的每个增强。
【问题讨论】:
【参考方案1】:如果不详细说明问题所在,我无法判断问题可能是什么。你有错误吗?可以发一些代码吗?
你有这样的东西吗?
json.getJSONObject("augment-list").getJSONArray("augment").getJSONObject(0).getInt("id")
【讨论】:
以上是关于在java中解析JSON的主要内容,如果未能解决你的问题,请参考以下文章