gpt4 book ai didi

iphone - URLWithString : returns nil

转载 作者:IT老高 更新时间:2023-10-28 11:20:33 28 4
gpt4 key购买 nike

这可能很容易,但我似乎不明白为什么 URLWithString: 在这里返回 nil。

//localisationName is a arbitrary string here
NSString* webName = [localisationName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString* stringURL = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@,Montréal,Communauté-Urbaine-de-Montréal,Québec,Canadae&output=csv&oe=utf8&sensor=false&key=", webName];
NSURL* url = [NSURL URLWithString:stringURL];

最佳答案

您还需要转义硬编码 URL 中的非 ASCII 字符:

//localisationName is a arbitrary string here
NSString* webName = [localisationName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString* stringURL = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@,Montréal,Communauté-Urbaine-de-Montréal,Québec,Canadae&output=csv&oe=utf8&sensor=false", webName];
NSString* webStringURL = [stringURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL* url = [NSURL URLWithString:webStringURL];

您可能可以删除 localisationName 的转义,因为它将通过整个字符串的转义来处理。

关于iphone - URLWithString : returns nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1981390/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com