Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone iOS从网络问题下载数据,NSURL_Iphone_Ios_Download_Nsurl - Fatal编程技术网

Iphone iOS从网络问题下载数据,NSURL

Iphone iOS从网络问题下载数据,NSURL,iphone,ios,download,nsurl,Iphone,Ios,Download,Nsurl,需要你的快速建议。我正在创建一个“货币转换器”iPhone应用程序,从谷歌货币网站检索数据。下载美元->澳元,美元->加元,美元->港币,美元->匈牙利法郎,美元->日元的字符串是完美的。但是,我不知道为什么在尝试检索USD->KRW和USD->ZMK时,不工作并返回NULL。请参考下面的代码 -(void)loadData:(NSString*)countryName{ self.responseData = [NSMutableData data]; NSStrin

需要你的快速建议。我正在创建一个“货币转换器”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
,因为它们是异步发送的,它们将在随机时间完成,并且您可能正在
responseData
中写入所有接收到的数据(来自所有请求)。每个请求都应该有自己的资源(
resourceData
connection


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

是的,对我来说似乎也没问题。。。然而,不知道为什么不工作。。。。真奇怪。。。你认为这是因为它返回的字符串大小吗??因为USD->KRW USD->ZMK之间的差异是返回值为4个正数字。其他小于3个正数字。。。