access NSDictionary content
I have an NSDictionary like
{
nodeAttributeArray = (
{
attributeName = ReportDate;
nodeContent = "08-31-1986";
},
{
attributeName = ReportType;
nodeContent = PQ1;
}
);
nodeName = Period;
},
{
nodeAttributeArray = (
{
attributeName = ReportDate;
nodeContent = "08-31-1987";
},
{
attributeName = ReportType;
nodeContent = PQ2;
}
);
nodeName = Period;
}
I have shown 2 values here. But there are almost 50 such members inside my dict How do开发者_运维百科 I access the contents of this inside a for loop ?
I want the value inside "nodeContent"
Thank you.
From looking at the data structure, it seems to me that the root structure is a List and not a dictionary as you pose in the question. Is that correct? If that is the case, then an iteration for printing the attribute values to the console would be:
NSArray *array; // this is your list with 50 values or so in it
//... some code to load the data into array
NSDictionary *d;
for (NSDictionary *period in array){
NSLog(@"%@",[period objectForKey:@"nodeName"]);
for (NSDictionary *nodeAttributeArray in [period objectForKey:@"nodeAttributeArray"]){
NSLog(@"\t%@=%@",[nodeAttributeArray objectForKey:@"attributeName"],[nodeAttributeArray objectForKey:@"nodeContent"]);
}
}
精彩评论