嵌套数组如何读取子数组数据?

时间:2016-02-10 19:59:34

标签: arrays nested

这是我的嵌套完整数组数据。但是如何单独获取项目数据?

(
    {
    AID = 1;
    ASID = 2;
    IsMulti = 0;
    Items =         (
                    {
            ASDID = 5;
            DetailAR = A;
            DetailEN = A;
        },
                    {
            ASDID = 6;
            DetailAR = B;
            DetailEN = B;
        },
                    {
            ASDID = 7;
            DetailAR = C;
            DetailEN = C;
        },
                    {
            ASDID = 8;
            DetailAR = D;
            DetailEN = D;
        }
    );
    SpecAR = "Location Specs 2";
    SpecEN = "Location Specs 2";
  }
)

1 个答案:

答案 0 :(得分:0)

这是一个包含单个NSArray实例的NSDictionary实例。

可以使用以下方法检索每个NSDictionary

for (NSDictionary *dict in array) {

每个字典都包含许多不同的项目,并以其名称键入:

    NSNumber *aid = dict[@"AID"];
    NSArray *items = dict[@"Items"];

Items数组是一个字典数组:

    for (NSDictionary *item in items) {
        NSNumber *asid = item[@"ASID"];
        NSString *detailAR = item[@"DetailAR"];
    }
}

所有项目都是对象,因为Objective-C集合类只能保存对象。因此,数字为NSNumber个实例,字符串为NSString,数组为NSArray,字典为NSDictionary