Webservice向我发送了类似的JSON:
[
{"key":"key1","value":"value1"},
{"key":"key2","value":"value2"},
{"key":"key3","value":"value3"}
]
我应该如何设置RestKit映射以获取以下NSDictionary?
@{ @"key1" : @"value1", @"key2" : @"value2", @"key3": @"value3" }
答案 0 :(得分: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];