【发布时间】:2018-05-13 20:15:10
【问题描述】:
我正在从服务器获取响应并将其转换为 NSDictionary。
Alamofire.request(URL, method: .post, parameters: parameters).responseJSON
{
response in
if let result = response.result.value {
let jsonData = result as! NSDictionary
let recordJSON=jsonData.value(forKey: "records") as! NSDictionary
let result = recordJSON.value(forKey: "result") as! NSArray
print(result)
}
}
现在结果中的值是
(
{
imagePath = "/SERVER/api/upload/geRsB.jpeg";
propertyId = 11;
userId = 5;
},
{
imagePath = "/SERVER/api/upload/RebJC.jpeg";
propertyId = 14;
userId = 5;
},
{
imagePath = "/SERVER/api/upload/fuM3F.jpeg";
propertyId = 18;
userId = 5;
}
)
那么,现在我如何从结果的每个索引中获取更多值(imagePath,propertyId,userId)。
提前致谢。
【问题讨论】:
-
不要在 Swift 中使用
NSDictionary和/或NSArray进行 JSON 解析。阅读Decodable上的文档以解析您的 JSON。