包含JSON对象的NSDictionary上的allKeys错误

时间:2013-02-25 15:27:56

标签: json nsarray nsdata

我尝试从url获取json数据,但是我得到了ERROR 这是我的代码;

self.NsData=[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://doctorapp.5plus.co.il/categories.php"]];
id jsonCategories=[NSJSONSerialization JSONObjectWithData:NsData options:NSJSONReadingMutableContainers error:nil];
self.categoriesArray=[jsonCategories allKeys];
NSLog(@"%@",[self.categoriesArray objectAtIndex:0]);

这是我的错误:

  

[__ NSArrayM allKeys]:无法识别的选择器发送到实例

1 个答案:

答案 0 :(得分:0)

self.data=[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://doctorapp.5plus.co.il/categories.php"]];
self.categoriesArray=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
self.categoriesNames=[[NSMutableArray alloc]init];
for (int i = 0; i < [self.categoriesArray count]; i++) {
        NSDictionary * dic = [self.categoriesArray objectAtIndex:i];
        NSString * k;
        for (k in [dic allKeys]) {
            [self.categoriesNames addObject:[dic objectForKey:k]];
            NSLog(@"Temporary ports: %@", [dic objectForKey:k]);
        }
}