【发布时间】:2016-12-10 15:01:53
【问题描述】:
这是我要解析的 json(示例):
[
{
"id": 1,
"name": "Team name",
"shower": {
"id": 1,
"status": 1,
"startLocation": {
"id": 1,
"name": "abc 16"
}
}
},
{
"id": 2,
"name": "Team name",
"shower": {
"id": 2,
"status": 1,
"startLocation": {
"id": 1,
"name": "efg 16"
}
}
}
]
- 粘贴this json viewer即可轻松查看。
如您所见,它是一个(团队)数组。 我需要让每个团队都参与其中。
经过多次尝试,我尝试使用SwiftyJSON,因为我认为它会更容易。但是,它对我不起作用。
这是我尝试过的:
let array = JSON(response)
// print each subJSON in array
for team in array.arrayValue {
print(team)
}
但循环不起作用。它根本不进入循环。 也许它不明白我的json是一个数组。
我可以在调试器中看到数组对象。它看起来像这样:
如何获取这些子 JSON?
谢谢。
【问题讨论】:
-
您的 JSON 无效。
"name": "abc 16"之后的行和之后的行不应该有逗号。 -
使用jsoneditoronline.org 这个来验证你的json。它在您的 json 字符串中显示错误。
-
要求您的服务器团队在每个创建问题的值之前删除额外的斜杠,因为 json 是键值对,但它似乎是无法获取的字符串
-
谢谢大家,我编辑并修复了 json 示例。
-
修复json字符串后还是不行?
标签: ios json swift swifty-json