【问题标题】:How to handle string response in swift 3 using alamofire如何使用 alamofire 在 swift 3 中处理字符串响应
【发布时间】:2017-04-17 08:47:28
【问题描述】:

我正在尝试点击响应为:

“dbdg96t7331e150600836bc5dc026cc1649a887fc8b921b6111172db399d03566a944946e3cd13246901128413c3c9673d4e806a4v7j2yxe”。

那么我该如何处理响应中的这个字符串呢?这是我的代码:

    temp = "Resident|" + user_uid
    let url = "http://api.appname.my/encodedecode.php?text=\(temp)"
    Alamofire.request(url).responseJSON { (responseObject) -> Void in
        print(responseObject)
    }

作为回应,我得到了这个:

失败:invalidURL("http://api.appname.my/encodedecode.php?text=Resident|uP6zkPihw1MPleJQ44WV1rsH1dO2")

【问题讨论】:

    标签: swift3 alamofire


    【解决方案1】:

    管道 (|) 需要在 URL 中转义

    temp = ("Resident|" + user_uid).addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!
    

    Alamofire.request 可能期望一个真正的URL 对象

    let url = URL(string: "http://api.appname.my/encodedecode.php?text=\(temp)")!
    

    【讨论】:

      猜你喜欢
      • 2014-11-15
      • 2020-12-02
      • 2019-02-10
      • 1970-01-01
      • 2018-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多