如何从NSDictionary中删除值?

时间:2013-12-09 09:28:44

标签: ios nsdictionary

大家好我在nslog返回以下内容时有字典值:

  

NSDictionary * dict = [NSJSONSerialization JSONObjectWithData:data1   选项:0错误:nil];                DLog(@“RESPONSE ======%@”,dict);

{
    errors =     (
                {
            "@msg" = "already exists";
            "@title" = "title";
        }
    ); }

如何从中提取msg密钥数据?

3 个答案:

答案 0 :(得分:3)

NSArray *array = dict[@"errors"];
NSDictionary *error1 = array[0];
NSString *msg = error1[@"@msg"];

NSString *msg现在包含already exists

答案 1 :(得分:0)

您可以像这样提取它:

NSString *msg = [myDictionary objectForKey:@"@msg"];

并删除如下:

[myDictionary removeObjectForKey:@"@msg"];

答案 2 :(得分:0)

NSDictionary dic2 = [dict objectforKey:@"errors"];
NSString* msg = [dict2 objectForKey:@"@msg"];