gpt4 book ai didi

swift - Alamofire Swift Json

转载 作者:行者123 更新时间:2023-11-30 11:45:01 25 4
gpt4 key购买 nike

我通过这种方法接收 Instagram JSON

Alamofire.request("https://www.instagram.com/", method: .get, encoding: JSONEncoding.default)
.responseJSON { response in
debugPrint(response)

if let data = response.result.value{

if (data as? [[String : AnyObject]]) != nil{

if let dictionaryArray = data as? Array<Dictionary<String, AnyObject?>> {
if dictionaryArray.count > 0 {

for i in 0..<dictionaryArray.count{

let Object = dictionaryArray[i]
if let dUrl = Object["display_url"] as? String{
print("Find: \(dUrl)")
}
if let id = Object["id"] as? String{
print("User Id: \(id)")
}
}
}
}
}
}
else {
let error = (response.result.value as? [[String : AnyObject]])
print(error as Any)
}
}

但是请帮助我。我如何收到:- ID和- display_resources[2]的第三个链接

最佳答案

SwiftyJSON 文档非常详细: https://github.com/SwiftyJSON/SwiftyJSON

let json = JSON(response.result.value ?? [])
let id = json["shortcode_media"]["id"].stringValue
let url = json["shortcode_media"]["display_url"]["display_resources"][2]["src"].stringValue

关于swift - Alamofire Swift Json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48944024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com