I have a api which needs to use a url string in order to work (wouldn't work with the normal NSDictionary request). The string I'm trying to use is

http://10.1.10.25:8181/config?param={"obj":["hours"]}

However, the following code which I used to escape the characters does not work. It returns a bad url error. What is the proper way to escape characters here?

NSURL *url = [NSURL URLWithString:@"http://10.1.10.25:8181/config?param={\"obj\":[\"hours\"]}"];
// Error: Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x8ca3780 {NSUnderlyingError=0x8ca6980 "bad URL", NSLocalizedDescription=bad URL}

Below is a picture of a working example using a online REST service. this works

有帮助吗?

解决方案

In this case you just need to encode your param like this: http://10.1.10.25:8181/config?param=%7B%22obj%22%3A%5B%22hours%22%5D%7D

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top