-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x8943940 while parsing JSON Page to UITableView

不羁的心 提交于 2019-12-02 03:21:22

Your JSON structure is something like this:

Dictionary-->Array-->Object (Dictionary).

So you need to do:

  1. Extract the Array from the dictionary using the key product
  2. Extract an object(Dictionary) from the array using the index
  3. Get the name from the dictionary object using the key name

Instead of this:

NSDictionary *myDict = [news objectAtIndex:indexPath.row];
NSArray *myArray = [myDict objectForKey:@"name"];

Use:

NSArray *myArr = [news objectForKey:@"products"];
cell.textLabel.text = [[myArr objectAtIndex:0] objectForKey:@"name"];

Edit

Also change your numberOfRowsInSection like:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[news objectForKey:@"products"] count];
}

news is a NSDictionary, and a dictionary does not have a method objectAtIndex:
You have to use instead [news objectForKey:...];

[news objectAtIndex:indexPath.row];

NSMutabledictionary is indexpath.row so add first news in array and that array name add in your code and you get nothing an

Put NSDictionary in Array then use it in Table method

 NSMutableArray *result=[[NSMutableArray alloc] init];
  result = [googleResponse valueForKey: @"products"];


 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSMutableDictionary *dt = [result objectAtIndex:indexPath.row];

}  

It will Help you !!!!!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!