JSON
{
"321" : {
"title" : "xyz",
"pageid" : 321,
"ns" : 0
},
"172" : {
"pageimage" : "xyzc.jpg",
"pageid" : 172,
"title" : "xyzcc",
"ns" : 0,
"thumbnail" : {
"width" : 100,
"height" : 57,
"source" : "https:\/\/upload.abcd.org\/wikipedia\/commons\/thumb\/d\/de\/xyz.jpg\/100px-xyz.jpg"
}
},
"224" : {
"pageimage" : "abc.jpg",
"pageid" : 224,
"title" : "dasf",
"ns" : 0,
"thumbnail" : {
"width" : 98,
"height" : 100,
"source" : "http:\/\/example.org\/images\/thumb\/2\/26\/skfdb.jpg\/98px-586px-dasdfsa.jpg"
}
},
"825" : {
"title" : "efkjdsb",
"pageid" : 825,
"ns" : 0
},
"229" : {
"title" : "eafewg",
"pageid" : 229,
"ns" : 0
}
使用 SwiftyJSON
从 JSONresponse 检索后,如何访问 JSON 文件中的“标题”和“缩略图”:“源”?
“321”、“172”可以改变并取决于。相同格式的数组中有多个对象。
有些对象有缩略图对象,有些则没有。
如何将 title
和 thumbnail->source
提取到带有图像和标签的 TableView
以创建列表。
(使用Swift
语言)
我正在使用 AFNetworking
let manager = AFHTTPSessionManager()
manager.GET(url, parameters: nil, success: {(operation, responseObject) -> Void in
let responsejson = JSON(responseObject!)
print("\n \n \n \n \n \n Retrieved = \n\(responsejson)")
let items = responsejson.count
print("Items : \(items)")
提前致谢。
最佳答案
您可以使用这样的代码来获取每个值:
for (key,obj) in responsejson {
print(obj["title"])
print(obj["thumbnail"]["source"])
}
关于ios - 使用 swiftyjson 从索引对象数组 ios 的 json 中检索标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41010029/