读取NSString时,解析的TouchXML XML文件崩溃

时间:2011-11-03 18:11:20

标签: objective-c xml nsstring nsmutablearray touchxml

我能够使用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);

请问,我该如何解决这个问题?谢谢!

1 个答案:

答案 0 :(得分:1)

TouchXML会返回一组NSDictionaries。要提取字符串,您需要从此NSDictionary中获取值:

NSString *url = [[res objectAtIndex:0] objectForKey:@"href"];