代码之家  ›  专栏  ›  技术社区  ›  Selvakumar

SWIFT URL字符串生成

  •  2
  • Selvakumar  · 技术社区  · 8 年前

    /sap/opu/odata/SAP/ZTM_FOR_MOBILITY_SRV/BusinessPartnerSet('BP-CR-EM01')/?$format=json
    

    我特别想要part-BusinessPartnerSet(“BP-CR-EM01”)。

    BP-CR-EM01值为动态值。

    let newUrl = url  + "'\(businessPartners[myIndex].partnerId)'"
    

    url具有固定url和+运算符,后跟动态值。请帮我提建议。

    1 回复  |  直到 8 年前
        1
  •  4
  •   vadian    8 年前

    我建议使用 URLComponents

    var components = URLComponents(string: "http://mycompany.com")!
    components.path = "/sap/opu/odata/SAP/ZTM_FOR_MOBILITY_SRV/BusinessPartnerSet('\(businessPartners[myIndex].partnerId)')/"
    components.queryItems = [URLQueryItem(name: "$format", value:"json")]
    if let url = components.url {
        print(url)
        // or if you need the string
        print(url.absoluteString)
    }
    
    推荐文章