问题描述
我正在尝试从xml Web服务解析数据,但无法获取我的URL.请检查我的代码:
I am trying to parse data from a xml web service but I am not able to get my url. Please check my code:
NSLog(@"log url: %@",url);
[url stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
NSLog(@"%@",url);
[url stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSLog(@"%@",url);
NSURL *URL = [NSURL URLWithString:url];
NSXMLParser *home_Parser = [[NSXMLParser alloc] initWithContentsOfURL:URL];
[home_Parser setDelegate:self];
[home_Parser parse];
[home_Parser release];
我总是将URL设为nil.原因是我的字符串url包含空格.我试图替换它并逃脱它,但是它不起作用.以下是我正在使用的网址
I am always getting URL as nil. The reason is my string url has space included. I have tried to replace it and escape it but it is not working. Following is the url that I am using
http://www.mydomain.com/radioListGenre.php?genre=Radiostations 玩摇滚如何删除该空间.还有我上面使用的其他技术.
http://www.mydomain.com/radioListGenre.php?genre=Radiostations playing Rockhow can I remove this space. Is there any other technique the those I used above.
谢谢
潘卡(Pankaj)
Thanks
Pankaj
推荐答案
stringByAddingPercentEscapesUsingEncoding
和 stringByReplacingOccurrencesOfString
对提供的字符串进行操作,并返回字符串.您没有将返回值分配给任何内容,因此url不变,返回值只是消失在空间中.您想要更多类似的东西:
stringByAddingPercentEscapesUsingEncoding
and stringByReplacingOccurrencesOfString
operate on the string provided and return a string. You're not assigning the return value to anything so url isn't changing, the return value is just vanishing into space. You want something more like:
url = [url stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
假设url是可变的字符串.现在url包含url的修改版本.没有分配,它的作用与执行以下操作相同:
assuming url is a mutable string. Now url contains the modified version of url. Without the assignment it's effective the same as doing something like this:
a + 1;
代替:
a = a + 1
这篇关于无法创建有效的nsurl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!