xcode 目标 C 中的数组到字典

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12012986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:15:33  来源:igfitidea点击:

Array to Dictionary in Objective C

objective-ciosxcodensdictionary

提问by keji

I have an array that outputs in NSLog:

我有一个在 NSLog 中输出的数组:

log: (
        {
        "case_color" = White;
        "case_description" = "";
        "case_image" = "http://site.com/get/parts/part_images/nzxtphantom410.jpeg";
        "case_name" = "NZXT Phantom 410";
        "case_price" = "99.99";
        "case_type" = ATX;
        id = 1;
    }
)

How can I put this in a NSDictionary so I can call it like:

我怎样才能把它放在 NSDictionary 中,所以我可以这样称呼它:

NSDictionary *object;
NSString *casename object[@"case_name"];

and casename is equal to "NZXT Phantom 410"

并且 casename 等于“NZXT Phantom 410”

回答by rob mayoff

It looks like your array has a single element which is a dictionary. Try this:

看起来您的数组有一个元素,它是一个字典。尝试这个:

NSDictionary *dictionary = [myArray objectAtIndex:0];
NSString *caseName = [dictionary objectForKey:@"case_name"];