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

Time:11-17

I need to make a URL with query parameter with large bracket. this is the example.

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

I trying to use URLComponents and URLQueryItem. but URLQueryItem don't take array (["code"] in below) as a value.

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

Does anybody hove idea for that?

CodePudding user response:

As @Alexander mentioned

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

was enough for this.

CodePudding user response:

The [] has no special meaning. This is just:

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