【发布时间】:2017-04-16 23:28:10
【问题描述】:
在我的swift 应用程序中,我使用的是SwiftyJSON 和Alamofire。
我有一个从后端返回到应用程序的 json:
{
"responses" : [
{
"labelAnnotations" : [
{
"mid" : "\/m\/01yrx",
"score" : 0.8735667499999999,
"description" : "cat"
},
{
"mid" : "\/m\/0l7_8",
"score" : 0.7697883,
"description" : "floor"
},
{
"mid" : "\/m\/01c34b",
"score" : 0.7577944,
"description" : "flooring"
},
{
"mid" : "\/m\/03f6tq",
"score" : 0.52875614,
"description" : "living room"
},
{
"mid" : "\/m\/01vq3",
"score" : 0.52516687,
"description" : "christmas"
}
]
}
]
}
我想构造一个包含上述每个描述的Strings 数组。
我试图用代码解析它:
{
case .success:
print("sukces")
if let jsonData = response.result.value {
let data = JSON(jsonData)
print(data)
if let responseData = data["responses"] as? JSON{
if let responseData2 = responseData["labelAnnotations"] as? JSON{
for userObject in responseData2 {
print(userObject["description"])
}
}
}
}
case .failure(let error):
print("fail")
print(error)
}
}
但是print(userObject) 行返回空字符串。如何显示每个描述?一旦我可以在控制台中打印它,我就会将它添加到我的数组中。
【问题讨论】:
标签: swift swift3 alamofire swifty-json