NSURL类

作者:追风剑情 发布于:2019-3-6 11:25 分类:Objective-C

通过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;
}

运行测试
111.png

标签: Objective-C

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号