【问题标题】:How can I make URLQueryItem with large bracket ([])?如何使用大括号 ([]) 制作 URLQueryItem?
【发布时间】:2021-11-16 01:50:12
【问题描述】:

我需要创建一个带有大括号的查询参数的 URL。 这是一个例子。

https://samlpe.com/detail?item_code[]=smtwGBArkp3ByfrLK3KfxdoX

我尝试使用 URLComponents 和 URLQueryItem。但 URLQueryItem 不将数组(下面的["code"])作为值。

var urlComponents = URLComponents(url: URL(string: "https://samlpe.com/detail")!,
                                                        resolvingAgainstBaseURL: false)
        urlComponents.queryItems = [URLQueryItem(name: "item_code", value: ["code"])]

有人对此有想法吗?

【问题讨论】:

  • @Alexander 我明白了,是的,它正在工作。谢谢!。
  • 我把我的评论变成了一个你可以投票和接受的答案

标签: swift urlcomponents


【解决方案1】:

[] 没有特殊含义。这只是:

URLQueryItem(name: "item_code[]", value: "smtwGBArkp3ByfrLK3KfxdoX")

【讨论】:

    【解决方案2】:

    正如@Alexander 提到的

    URLQueryItem(name: "item_code[]", value: "smtwGBArkp3ByfrLK3KfxdoX")
    

    足够了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-11
      • 1970-01-01
      • 2015-01-02
      • 2022-11-30
      • 2011-01-12
      • 2011-09-26
      • 1970-01-01
      相关资源
      最近更新 更多