【发布时间】:2016-12-20 13:50:49
【问题描述】:
我正在用 Swift 接收以下 JSON 文件,但我不知道如何获取 JSON 中的详细信息元素
[
{
"id": 143369,
"history": "jd2",
"details": [
{
"name": "Su 1",
"color": "#ffffff"
},
{
"name": "Stu 1",
"color": "#ffffff"
}
]
},
{
"id": 143369,
"history": "musa 2",
"details": [
{
"name": "Stu 1",
"color": "#ffffff"
},
{
"name": "Stu 2",
"color": "#ffffff"
}
]
}
]
我创建了这个类,我可以用它来检索 id 和历史记录,但不能检索详细信息。如何在 id 和历史记录中包含详细信息?
public class students {
let id: Int32
let history: String?
init(id:Int32, history:String) {
self.id = id
self.history = name
}
}
下面是我的网络服务代码。
var dataArray = [students]()
Alamofire.request(.GET, url)
.responseJSON { response in
if let value: AnyObject = response.result.value {
let json = JSON(value)
if let items = json.array {
for item in items {
self.dataArray.append(students(
id: item["id"].int32!,
history: item["history"].string!))
let cItems = item["details"].array
for citem in citems {
//here
}
}
}
}
}
【问题讨论】:
-
您想使用Object Mapper 吗?如果是,那么我可以发布答案
标签: json swift dictionary