gpt4 book ai didi

iphone - 尝试将用户输入放入 yahoo api URL 中

转载 作者:行者123 更新时间:2023-11-29 03:42:08 29 4
gpt4 key购买 nike

我正在尝试学习ios,我的第一个项目是制作一个应用程序,显示用户输入的邮政编码区域的天气预报。

我的网址是:

NSString *zipUrl = @"http://query.yahooapis.com/v1/public/yql?q=select%20item%20from%20weather.forecast%20where%20location%3D%2289448%22&format=json";

邮政编码接近 3D%22 后面的末尾:

3D%22*89448*%22

我只需要弄清楚如何将用户在文本框中输入的内容插入到此位置。我已经尝试过 [NSString StringWithFormat] ,但有很多 % 符号表明它不起作用。

如果您需要更多信息,请告诉我。

最佳答案

您需要首先解码 zipUrl,因为它编码字符串。

NSString *zipUrl = @"http://query.yahooapis.com/v1/public/yql?q=select%20item%20from%20weather.forecast%20where%20location%3D%2289448%22&format=json";

NSString *decodedString= [[NSString stringWithFormat:@"%@",zipUrl] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"decodedString : %@",decodedString);

NSString *myStringURL = [NSString stringWithFormat:@"http://query.yahooapis.com/v1/public/yql?q=select item from weather.forecast where location=%@&format=json",yourtextfield.text];

希望对你有帮助。

关于iphone - 尝试将用户输入放入 yahoo api URL 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18266888/

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