0

Webservice 向我发送如下所示的 JSON:

[
    {"key":"key1","value":"value1"},
    {"key":"key2","value":"value2"},
    {"key":"key3","value":"value3"}
]

我应该如何设置 RestKit 映射以获取以下 NSDictionary?

@{ @"key1" : @"value1", @"key2" : @"value2", @"key3": @"value3" }
4

1 回答 1

1

这可能对你有帮助,试试这个。

    NSDictionary *dict1 = [[NSMutableDictionary alloc] init];
            NSArray *arr = [[NSArray alloc] initWithArray:<Parse the array here from RESTkit>];
            for (int i = 0;i < [arr count], i++)
            {
                NSDictionary *dict = [arr objectAtIndex:i];
                NSString *key = [dict objectForKey:@"key"];
                NSString *value = [dict objectForKey:@"value"];
                [dict1 setObject:value forKey:key];

            }

        NSLog(@" Dictionary %@", dict1);
[dict1 release];
于 2013-01-14T12:49:27.147 回答