我想使用JSON长度在表视图中显示数据,但我不知道如何在json中获取长度
let url = "url/json.php"
Alamofire.request(.GET, url, parameters: ["id":ids])
.responseJSON { response in
print(response.request) // original URL request
print(response.response) // URL response
print(response.data) // server data
print(response.result) // result of response serialization
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}
示例
{a=11,b=12},{a=21,b=22}
length = 2
答案 0 :(得分:0)
您需要将JSON常量值解析为数组。
答案 1 :(得分:0)
斯威夫特3:
{ response in
if let allObjects = response.result.value as? NSArray{
print("Array length is \(allObjects.count)")
}
}