首页 > 解决方案 > 如何在字典中写入属性数组

问题描述

我需要在数组里面输入一个属性值怎么办??

我试图在字典中显式添加数组

NSDictionary *uilabeldropdown = @{ 
    @"UILabelDropDownWithTextField" : @{                                              
        @"headingLabel" : @{                                                      
            @"localizationKey" : @"Number"                                                      
        },
        @"userTextField" : @{                                                     
            @"xpath" : @"Home"                                                      
        },
        @"contentArray" : @[                                                     
            @"item 0":@"Home",                                                      
            @"item 1":@"New",                                                      
            @"item 2":@"ground"                                                      
        ]
    }
};

标签: objective-c

解决方案


@[...]是 an 的语法NSArray,它不支持字符串键。

@"contentArray" : @[                                                     
    @"item 0":@"Home",                                                      
    @"item 1":@"New",                                                      
    @"item 2":@"ground"                                                      
]

删除键并按索引访问值。

@"contentArray" : @[
    @"Home",
    @"New",
    @"ground"
]

uilabeldropdown[@"contentArray"][0]

推荐阅读