如何制作带有大括号 ([]) 的 URLQueryItem?

How can I make URLQueryItem with large bracket ([])?

我需要制作一个 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 提到的那样

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

够了。

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

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