Can't extract needed information from NSDictionary

前端 未结 2 1549
后悔当初
后悔当初 2021-01-27 08:29

I parse a XML file, and after parsing get a NSDictionary object (XMLDictionary named). I\'m parsing this:

27

        
相关标签:
2条回答
  • 2021-01-27 09:13
    NSError* parseError = nil;
    _xmlDictionary = [XMLReader dictionaryForXMLString:myXMLString error:&parseError];
    if (parseError != nil) {
        NSLog(@"Error on XML parse: %@", parseError);
    }
    
    NSLog(@"The full dictionary is %@", _xmlDictionary);
    
    NSDictionary* result = [_xmlDictionary objectForKey:@"result"];
    NSLog(@"'result' = %@", result);
    NSDictionary* node = [result objectForKey:@"node"];
    NSLog(@"'node' = %@", node);
    NSString* name = [node objectForKey:@"name"];
    NSLog(@"'name' = %@", name);
    

    At the very least, if it fails, the error will be isolated to a single operation. And the NSLogs will show you the values after each step.

    0 讨论(0)
  • 2021-01-27 09:15

    Try this:

    NSArray *arrResult = [_xmlDictionary objectForKey:@"result"];
    for(int i = 0; i < [arrResult count]; i++)
    {
        NSArray *arrNode = [arrResult objectAtIndex:i] valueForKey:@"node"];
        NSString *sName = [arrNode valueForKey:@"Name"];
        NSLog(@"Name : %@",sName);
    }
    

    Edited Answer

      NSArray *arrResult = [_xmlDictionary valueForKey:@"result"];
        for (int i = 0; i < [arrResult count]; i++) {
            NSDictionary *dicNode = [[arrResult objectAtIndex:i] valueForKey:@"Node"];
            NSString *sName = [dicNode valueForKey:@"Name"];
            NSLog(@"Name : %@",sName);
        }
    
    0 讨论(0)
提交回复
热议问题