ios带有字符串的压缩说明符无效

时间:2014-07-16 13:18:42

标签: ios objective-c url

我有一个网址字符串:

[NSString stringWithFormat:@"https://gmt.telekom-dienste.de/query?callback=jQuery16203304807513486594_1405512207013&gmt_request=%7B%22boundary%22%3A%7B%22n%22%3A52.84508248794807%2C%22s%22%3A52.16803549716245%2C%22w%22%3A12.379694196093737%2C%22e%22%3A14.472589703906237%7D%2C%22queries%22%3A%5B%7B%22type%22%3A%22points%22%2C%22layer%22%3A%22shops1%22%7D%2C%7B%22type%22%3A%22points%22%2C%22layer%22%3A%22shops2%22%7D%2C%7B%22type%22%3A%22points%22%2C%22layer%22%3A%22shops3%22%7D%5D%7D&zoom=9&_=1405512557274"]

但是xcode在_request=%7B%22boundary中填写了无效的压缩说明符B并切断了网址 有什么问题?

3 个答案:

答案 0 :(得分:0)

检查

`NSURL *url = [NSURL URLWithString: @"https://gmt.telekom-dienste.de/query?callback=jQuery16203304807513486594_1405512207013&gmt_request=%7B%22boundary%22%3A%7B%22n%22%3A52.84508248794807%2C%22s%22%3A52.16803549716245%2C%22w%22%3A12.379694196093737%2C%22e%22%3A14.472589703906237%7D%2C%22queries%22%3A%5B%7B%22type%22%3A%22points%22%2C%22layer%22%3A%22shops1%22%7D%2C%7B%22type%22%3A%22points%22%2C%22layer%22%3A%22shops2%22%7D%2C%7B%22type%22%3A%22points%22%2C%22layer%22%3A%22shops3%22%7D%5D%7D&zoom=9&_=1405512557274"];`

答案 1 :(得分:0)

在你的字符串中,%22表示双引号(“)。这意味着你的字符串值在此之前结束。这就是问题。

答案 2 :(得分:0)

无效的压缩说明符B - 这是因为字符串包含'%'标志。和B被视为格式说明符。并且没有这样的格式说明符。

实际问题是你的字符串有'%'。百分号的转义码是" %%"。所以,为了使NSString正确,你应该替换'%'与' %%'。

但是如果你用这个字符串制作NSURL,那么你可以直接使用它 -

 NSURL *url = [NSURL URLWithString: @"https://gmt.telekom-dienste.de/query?callback=jQuery16203304807513486594_1405512207013&gmt_request=%7B%22boundary%22%3A%7B%22n%22%3A52.84508248794807%2C%22s%22%3A52.16803549716245%2C%22w%22%3A12.379694196093737%2C%22e%22%3A14.472589703906237%7D%2C%22queries%22%3A%5B%7B%22type%22%3A%22points%22%2C%22layer%22%3A%22shops1%22%7D%2C%7B%22type%22%3A%22points%22%2C%22layer%22%3A%22shops2%22%7D%2C%7B%22type%22%3A%22points%22%2C%22layer%22%3A%22shops3%22%7D%5D%7D&zoom=9&_=1405512557274"];