NSURLRequest Null(无编码问题)

时间:2012-05-29 17:14:34

标签: ios xml nsstring nsurlrequest

问题:

NSString *str = [[NSString alloc] initWithString:theList.artist];
NSLog(@"%@",str);     // Log gives me the correct string...

NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:str]];
[self.webView loadRequest:request]; 
NSLog(@"%@", request);      //Log returns <NSURLRequest (null)>

然后,如果我尝试:

NSString *str = [[NSString alloc] initWithString:@"http://totssants.com/index.html"];
                                       //which is the actual URL I am trying to load

一切都很顺利...我可以将字符串传递给其他地方但不是请求... 可能是我正在解析的XML问题吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

尝试

NSString *str = [theList.artist stringByReplacingOccurrencesOfString:@"\n" withString:@""];
str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

确保theList.artist的开头或结尾没有空格。这也会搞砸了。不止一次发生在我身上。