读取 NSString 时解析的 TouchXML XML 文件崩溃
我能够使用 TouchXML 成功解析 XML 文件的内容,但是当我尝试从存储解析内容的 NSMutableArray 读取单个 NSString 时,iPhone 应用程序崩溃。
我的 NSLog 向我显示该文件已按应有的方式进行解析,并给出以下输出:
(
{
href = "mms://a19349.l412964549958.c41245496.f.lm.akamaistream.net/D/194359/4125596/v0001/reflector:49944";
},
{
href = "mms://a4322.l4129624350471.c414645296.a.lm.akamaistream.net/D/473432/4129566/v0001/reflector:546441";
} )
这是我用来进行解析的代码:
NSMutableArray *res = [[NSMutableArray alloc] init];
.... Parsing happens here ....
然后我尝试使用此代码从 NSMutableArray 中检索字符串(应用程序崩溃了)当尝试阅读这行代码时,发布在下面 NSMutableString *string1 = [NSMutableString stringWithString:url];
NSString *url = [[NSString alloc] init];
url = [res objectAtIndex:0];
NSMutableString *string1 = [NSMutableString stringWithString:url];
[string1 deleteCharactersInRange: [string1 rangeOfString: @"href = "]];
[string1 deleteCharactersInRange: [string1 rangeOfString: @";"]];
NSLog(@"Clean URL: %@", string1);
请问,我该如何解决这个问题,谢谢!
I'm able to successfully parse the contents of a XML file using TouchXML, but when I try to read an individual NSString, from the NSMutableArray that stores the parsed content, the iPhone app crashes.
My NSLog shows me that the file has been parse as it should, giving this output:
(
{
href = "mms://a19349.l412964549958.c41245496.f.lm.akamaistream.net/D/194359/4125596/v0001/reflector:49944";
},
{
href = "mms://a4322.l4129624350471.c414645296.a.lm.akamaistream.net/D/473432/4129566/v0001/reflector:546441";
} )
Here is the code I'm using to do the parsing:
NSMutableArray *res = [[NSMutableArray alloc] init];
.... Parsing happens here ....
Then I try to retrieve the string from the NSMutableArray, using this code (and the app crashes when trying to read this line of code, posted below NSMutableString *string1 = [NSMutableString stringWithString:url];
NSString *url = [[NSString alloc] init];
url = [res objectAtIndex:0];
NSMutableString *string1 = [NSMutableString stringWithString:url];
[string1 deleteCharactersInRange: [string1 rangeOfString: @"href = "]];
[string1 deleteCharactersInRange: [string1 rangeOfString: @";"]];
NSLog(@"Clean URL: %@", string1);
Please, how can I solve this problem? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TouchXML 返回一个 NSDictionaries 数组。为了提取字符串,您需要从此 NSDictionary 中获取值:
TouchXML returns you an array of NSDictionaries. In order to extract string you need to take value from this NSDictionary: