While implement the code below, I got itemCount = 3, but it should be itemCount = 1 because I point to Banner > Banner. Did anyone know why I got this result and any fix for it?
Thanks
NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLData:contents error:&parseError];
NSLog(@"xmlDictionary = %@", xmlDictionary);
int itemCount = [[[xmlDictionary objectForKey:@"Banner"] objectForKey:@"Banner"] count];
NSLog(@"itemCount = %d", itemCount);
LOG:
2012-03-02 12:54:49.728 BROADWAY[541:ef03] xmlDictionary = {
Banner = {
Banner = {
date = {
text = "\n 29/02/2012";
};
name = {
text = "\n \n iPhone_Banner_HSB.jpg";
};
text = "\n ";
};
text = "\n";
};
}
2012-03-02 12:54:49.728 BROADWAY[541:ef03] itemCount = 3
The count of a dictionary is the number of keys in the dictionary.
The top-level dictionary has one key:
Banner.That key’s value is a dictionary with two keys:
Bannerandtext.The second
Bannerkey’s value is a dictionary with three keys:date,name, andtext. This is the dictionary that you counted.