Question

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!

Was it helpful?

Solution

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"];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top