gpt4 book ai didi

iphone - iOS 从网页下载数据的问题,NSURL

转载 作者:行者123 更新时间:2023-11-29 04:57:49 26 4
gpt4 key购买 nike

需要您的快速建议。我正在创建一个“货币转换器”iPhone 应用程序来从谷歌货币网站检索数据。下载美元->澳元、美元->加元、美元->港元、美元->匈牙利福林、美元->日元等字符串是完美的。但是,我不明白为什么在尝试检索 USD->KRW 和 USD->ZMK 时工作并返回NULL。请引用以下代码。

 -(void)loadData:(NSString*)countryName{
self.responseData = [NSMutableData data];
NSString *responseURL = [NSString stringWithFormat: @"http://www.google.com/ig/calculator?q=1USD=?%@", countryName];
NSLog(@"URL:%@", responseURL);

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:responseURL]];

theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];

NSString* responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"This is the responseString %@", responseString);
[responseString release];


}
- (void)viewDidLoad {
[super viewDidLoad];
[self loadData:@"AUD"];
[self loadData:@"CAD"];
[self loadData:@"HKD"];
[self loadData:@"HUF"];
[self loadData:@"JPY"];
[self loadData:@"KRW"];
[self loadData:@"ZMK"];
}

控制台结果:

 2011-09-30 18:03:50.877 Converter[1691:f503] URL:http://www.google.com/ig/calculator?q=1USD=?AUD
2011-09-30 18:03:50.879 Converter[1691:f503] URL:http://www.google.com/ig/calculator?q=1USD=?CAD
2011-09-30 18:03:50.879 Converter[1691:f503] URL:http://www.google.com/ig/calculator?q=1USD=?HKD
2011-09-30 18:03:50.879 Converter[1691:f503] URL:http://www.google.com/ig/calculator?q=1USD=?HUF
2011-09-30 18:03:50.879 Converter[1691:f503] URL:http://www.google.com/ig/calculator?q=1USD=?JPY
2011-09-30 18:03:50.879 Converter[1691:f503] URL:http://www.google.com/ig/calculator?q=1USD=?KRW
2011-09-30 18:03:50.879 Converter[1691:f503] URL:http://www.google.com/ig/calculator?q=1USD=?ZMK
2011-09-30 18:03:50.952 Converter[1691:f503] This is the responseString {lhs: "1 U.S. dollar",rhs: "1.02228583 Australian dollars",error: "",icc: true}
2011-09-30 18:03:50.962 Converter[1691:f503] This is the responseString {lhs: "1 U.S. dollar",rhs: "7.79149947 Hong Kong dollars",error: "",icc: true}
2011-09-30 18:03:50.966 Converter[1691:f503] This is the responseString {lhs: "1 U.S. dollar",rhs: "215.889465 Hungarian forints",error: "",icc: true}
2011-09-30 18:03:50.982 Converter[1691:f503] This is the responseString {lhs: "1 U.S. dollar",rhs: "1.03910031 Canadian dollars",error: "",icc: true}
2011-09-30 18:03:50.993 Converter[1691:f503] This is the responseString {lhs: "1 U.S. dollar",rhs: "76.5579544 Japanese yen",error: "",icc: true}
2011-09-30 18:03:51.010 Converter[1691:f503] This is the responseString (null)
2011-09-30 18:03:51.047 Converter[1691:f503] This is the responseString (null)

请帮忙,非常感谢。

最佳答案

您不应该与所有请求共享 responseData,因为它们是异步发送的,它们都会在随机时间完成,并且您可能正在写入所有收到的数据(来自所有请求)在响应数据中。每个请求都应该有自己的资源(resourceDatatheConnection)。

看看ASIHTTPRequest一个简单的解决方案。

关于iphone - iOS 从网页下载数据的问题,NSURL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7609115/

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