您好我试图从数组中解析parseJson
数据。我的问题是我不知道如何访问我的响应,因为它是一个位于另一个数组中的数组。
这是我的回答:
{
"finalResult": [
[
{
"Id":2,"latitude":"49.993820099043","longitude":"14.660662520439","usrId":2,"timeCreated":"2016-08-06 18:31:32"
}
],
[
{
"Id":3,"latitude":"49.993900553360","longitude":"14.660832398337","usrId":2,"timeCreated":"2016-08-06 18:29:37"
}
]
]
}
这是我需要帮助的代码的一部分:
if let parseJson = json {
if let events = parseJson["finalResult"] as? [AnyObject] {
for event in events {
for single in (event as? [AnyObject])! {
let Id = single["Id"] as! String
let latitude = single["latitude"] as! String
let longitude = single["longitude"] as! String
let usrId = single["usrId"] as! String
print(id)
print(latitude)
print(longitude)
print(usrId)
}
}
}
}
答案 0 :(得分:1)
for event in events {
if let customObjects = event as? [AnyObject] {
for customObject in customObjects {
let Id = customObject["Id"] as! String
let latitude = customObject["latitude"] as! String
let longitude = customObject["longitude"] as! String
let usrId = customObject["usrId"] as! String
print(id)
print(latitude)
print(longitude)
print(usrId)
}
}
}