NSString *string1=@"http://iosseventeenclass.sinaapp.com/index.php?name=林&age=25";
string1 =[string1 stringByAddingPercentEscapesUsingEncoding:4];//编码
NSURL *url=[NSURL URLWithString:string1];
NSData *data=[NSData dataWithContentsOfURL:url];
NSString *string=[[NSString alloc]initWithData:data encoding:4];//4表示中文编码:UTF8
NSLog(@"%@",string);
在OC中将URL字符串转换成NSURL时,其协议、主机域名、路径文件、查询条件都被封装成NSURL类中的属性,如下示:
NSLog(@"url absoluteString = %@",url.absoluteString); NSLog(@"url relativeString = %@",url.relativeString); NSLog(@"url scheme = %@",url.scheme); NSLog(@"url resourceSpecifier = %@",url.resourceSpecifier); NSLog(@"url host = %@",url.host); NSLog(@"url port = %@",url.port); NSLog(@"url user = %@",url.user); NSLog(@"url password = %@",url.password); NSLog(@"url query = %@",url.query);
url
最新推荐文章于 2024-09-05 07:30:00 发布