【发布时间】:2015-07-31 11:27:08
【问题描述】:
下面我发布了我的嵌套 JSON 响应。我想将所有键和键值加载到一个表视图中,如下面的 UI。请帮帮我!
我的 JSON
response : {
ANI = {
name = "anisharmu";
age = "10";
};
ROC = {
name = "rockins";
age = "20";
};
}
我的 UI 表格视图
|------------------------|
ANI anisharmu - 10
|------------------------|
我的代码
NSError *error;
jsonDictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
// get keys from response dictionary
NSMutableArray * key = [[NSMutableArray alloc] initWithArray:[jsonDictionary[@"response"] allKeys]];
// sort as asending order
NSSortDescriptor* sortOrder = [NSSortDescriptor sortDescriptorWithKey: @"self" ascending: YES];
key = (NSMutableArray *)[key sortedArrayUsingDescriptors: [NSArray arrayWithObject: sortOrder]];
// access inner data from dictonary
for (NSString * obj in key) {
NSLog(@"%@",jsonDictionary[@"response"][obj][@"name"]);
}
【问题讨论】:
-
我需要 Objective C 代码...@whirlwind
-
也许你可以试试这个:stackoverflow.com/questions/21207359/…
标签: ios objective-c json uitableview