尝试将JSON结果加载到数组中

时间:2013-05-29 18:32:43

标签: ios arrays afnetworking

我使用以下代码获取JSON结果但得到错误:-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance.我需要采用字符串格式的JSON并将其放入数组中以便我可以使用它。

我的refreshStream2方法如下

-(void)refreshStream2 
    {

 [[API sharedInstance] commandWithParams:[NSMutableDictionary dictionaryWithObjectsAndKeys:
                                             @"stream2",@"command",
                                             nil]
                               onCompletion:^(NSDictionary *json) {
                                   //got stream

  NSArray* list = [json objectForKey:@"result"];
                                NSLog(@"%@", list);
                                NSDictionary* photo = [list objectAtIndex:0];
                                NSLog(@"%@", photo);
                               [self showStream2:[photo objectForKey:@"Address"]];
     }];

}

然后我调用showStream2方法

-(void)showStream2:(NSArray*)stream {
     [_tableView reloadData];
     self.myList = [[NSMutableArray alloc] init];
     for (int i=0;i<10;i++) {
         NSDictionary* myTitle  = [stream objectAtIndex:i];   // I GET ERROR HERE!!
         [self.myList addObject: myTitle];
     }
 }

* JSON输出* * **

2013-05-29 13:06:05.581 app [16335:907]     (         {         地址= test2;         BarName = test1;     },         {         地址= test2;         BarName = test;     },         {         地址= test2;         BarName = test;     },         {         地址= test2;         BarName = test;     },         {         地址= test2;         BarName = test;     },         {         地址= test2;         BarName = test;     },         {         地址= test2;         BarName = test;     },         {         地址= test2;         BarName = test;     },         {         地址= test2;         BarName = test;     },         {         地址= test2;         BarName = test;     }     )

0 个答案:

没有答案