【问题标题】:Alamofire Swift JsonAlamofire Swift Json
【发布时间】:2018-02-23 08:36:31
【问题描述】:

我通过这种方法收到 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]的第三个链接

【问题讨论】:

    标签: swift instagram alamofire instagram-api swifty-json


    【解决方案1】:

    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
    

    【讨论】:

    • 返回空响应
    • 这个笔画工作让 id = json["graphql"]["shortcode_media"]["id"].stringValue
    • 这样的工作 let url = json["graphql"]["shortcode_media"]["display_resources"][2]["src"].stringValue 谢谢你
    猜你喜欢
    • 1970-01-01
    • 2020-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-18
    相关资源
    最近更新 更多