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

发布于 2024-12-13 22:53:15 字数 1090 浏览 0 评论 0原文

我能够使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫南 2024-12-20 22:53:16

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

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

TouchXML returns you an array of NSDictionaries. In order to extract string you need to take value from this NSDictionary:

NSString *url = [[res objectAtIndex:0] objectForKey:@"href"];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文