доступ к контенту NSDictionary - PullRequest
0 голосов
/ 23 января 2011

У меня есть NSDictionary вроде

{
        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;
    }

Я показал 2 значения здесь.Но в моем диктовке почти 50 таких членов. Как мне получить доступ к содержимому этого цикла for?

Мне нужно значение внутри "nodeContent"

Спасибо.

1 Ответ

1 голос
/ 23 января 2011

Из рассмотрения структуры данных мне кажется, что корневая структура - это список, а не словарь, как вы задаете в вопросе. Это верно? Если это так, то итерация для вывода значений атрибутов на консоль будет:

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"]);
    }
}
...