这个问题听起来很奇怪,但我得到了一系列字典作为解析结果。
像这样的东西:
parsed content: (
{
"name" = "John";
"lastname" = "Doe";
"foo" = "bar";
}
对于创建值数组的最佳方法有什么建议?
这个问题听起来很奇怪,但我得到了一系列字典作为解析结果。
像这样的东西:
parsed content: (
{
"name" = "John";
"lastname" = "Doe";
"foo" = "bar";
}
对于创建值数组的最佳方法有什么建议?
像这样?
- (void)flattenDictionary:(NSDictionary *)d intoKeys:(NSMutableArray *)keys andValues:(NSMutableArray *)values {
for (id key in [d allKeys]) {
[keys addObject:key];
[values addObject:[d valueForKey:key]];
}
}
- (void)flattenDictionaries:(NSArray *)arrayOfDictionaries {
NSMutableArray *keys = [NSMutableArray array];
NSMutableArray *values = [NSMutableArray array];
for (NSDictionary *d in arrayOfDictionaries) {
[self flattenDictionary intoKeys:keys andValues:values];
}
NSLog(@"now we have these values %@", values);
NSLog(@"corresponding to these keys %@", keys);
}
您可以通过以下方式获取值:
NSArray *values = dictionary.allValues;
或者,循环遍历它:
[dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id object, BOOL *stop) {
NSLog(@"%@ = %@", key, object);
}];
要通过它们循环并创建一个数组。