通过URL读取数据
示例
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSURL *myURL = [NSURL URLWithString: @"http://www.baidu.com"];
// 读取百度首页的html内容
NSString *myHomePage = [NSString stringWithContentsOfURL:
myURL encoding: NSASCIIStringEncoding error: NULL];
NSLog(@"%@", myHomePage);
// 从URL读取字典
//myURL = [NSDictionary dictionaryWithContentsOfURL: myURL];
// 从URL读取数组
//myURL = [NSArray arrayWithContentsOfURL: myURL];
// 从URL读取任意数据
//myURL = [NSData dataWithContentsOfURL: myURL options: NSDataReadingUncached error: NULL];
}
return 0;
}