我下载了一个包含 3 行的文件,其中包含 3 行,但我的数组似乎每组都跳过一行。在我的数组中,有形的结果出现在位置:0、2 和 4,而不是位置 0、1 和 2。
另外,这会在几秒钟后超时吗?我只看到一个间隔,是超时吗?
NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
NSNumber *timeStampObj = [NSNumber numberWithDouble: timeStamp];
NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://192.168.1.30/ios/info.php?a=APP1&s=%i",timeStampObj]];
NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:0 timeoutInterval:5];
NSURLResponse* response=nil;
NSError* error=nil;
NSData* data=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString* fileContents = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
if ([fileContents length] == 0) return;
NSArray* allLinedStrings = [fileContents componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
if ([allLinedStrings count] == 0) {
} else {
NSString* Title = [allLinedStrings objectAtIndex:0];
NSString* Description = [allLinedStrings objectAtIndex:2];
NSString* Url = [allLinedStrings objectAtIndex:4];
}