ios - NSDictionary 从一键到多键

标签 ios objective-c nsdictionary

<分区>


关闭 8 年前

我得到了 NSDictionary

Printing description of gameDict:
{
    result =     {
        developer = "Bethesda Game Studios";
        genre = "Role-Playing";
        name = "The Elder Scrolls V: Skyrim";
        platform = "PlayStation 3";
        publisher = "Bethesda Softworks";
        rating = M;
        rlsdate = "2011-11-11";
        score = 92;
        summary = "The next chapter in the Elder Scrolls saga arrives from the Bethesda Game Studios. Skyrim reimagines the open-world fantasy epic, bringing to life a complete virtual world open for you to explore any way you choose. Play any type of character you can imagine, and do whatever you want; the legendary freedom of choice, storytelling, and adventure of The Elder Scrolls is realized like never before. Skyrim's new game engine brings to life a complete virtual world with rolling clouds, rugged mountains, bustling cities, lush fields, and ancient dungeons. Choose from hundreds of weapons, spells, and abilities. The new character system allows you to play any way you want and define yourself through your actions. Battle ancient dragons like you've never seen. As Dragonborn, learn their secrets and harness their power for yourself.";
        thumbnail = "http://static.metacritic.com/images/products/games/6/372529409ea6cc3faadf5674fd96ba2a-98.jpg";
        url = "http://www.metacritic.com/game/playstation-3/the-elder-scrolls-v-skyrim";
        userscore = "6.3";
    };
}

它只得到一个关键的“结果” 我如何获得其他 key ?

最佳答案

gameDict 是具有一个键/对的 NSDictionary。键“结果”指向另一个 NSDictionary,它有更多的键。因此,要访问任何更深层次的键,您可以内联进行:

NSNumber *score = gameDict[@"result"][@"score"];

或者你也可以把字典拿出来查询

NSDictionary *resultDict = gameDict[@"result"];
NSNumber *score = resultDict[@"score"];

关于ios - NSDictionary 从一键到多键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29212198/

上一篇:ios - 继承自 UITextField 的类导致无法获取内容?

下一篇:具有额外填充的 UITableViewCell 内的 iOS Autolayout 2 多行 UILabel

相关文章:

objective-c - 在Sharekit2.0中自定义发到facebook的帖子

iOS:是否可以向 MKMapView 添加三次点击手势识别器?

iphone - 有没有一种简单的方法可以按键值对 plist(字典数组)进行排序?

ios - 我不知道如何在 Swift 中将屏幕截图发送到 Instagram 应用程序

iphone - 准备错误 : no such table: items

objective-c - 刷新核心数据关系

iphone - NSMutableArray 删除重复项

ios - 将 Char 或 NSString 添加到 Objective C 枚举中

objective-c - "data-only"Objective-C 对象的更好替代方案?

ios - 需要等待 Alamofire 请求完成才能继续 - Swift