【问题标题】:access NSDictionary content访问 NSDictionary 内容
【发布时间】:2011-01-23 09:02:36
【问题描述】:

我有一个类似的 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 循环中访问 this 的内容?

我想要“nodeContent”中的值

谢谢。

【问题讨论】:

    标签: iphone objective-c nsdictionary


    【解决方案1】:

    从查看数据结构来看,在我看来,根结构是 List 而不是您在问题中提出的字典。那是对的吗?如果是这种情况,那么将属性值打印到控制台的迭代将是:

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

    【讨论】:

    • 其实我不太确定..但这会由 XML 解析器返回,它说返回类型是 NSDictionary...(cocoawithlove.com/2008/10/…) 我刚刚在控制台中调试了它,它说; replist_rptdt_dict 的打印描述: ( { nodeAttributeArray = ( { attributeName = ReportDate; ......
    • 它说“返回的节点数组中的每个结果都将是一个具有以下结构的 NSDictionary:”
    • 在通常的表示法中,如果打印的数据结构以 '(' 开头,那么它是一个列表。使用 NSLog(@"%@",[obj class]);
    • 它表示 obj 类的“__NSArrayM”
    • 我有点困惑,因为在 .h 文件中我已将其设置为 dict。 NSMutableDictionary *replist_rptdt_dict;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-25
    • 2018-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多