我正在尝试学习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/