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

后端 未结 4 433
广开言路
广开言路 2021-01-24 14:43

I have been through many links and fortunately I got many similar links but nothing worked Out.

my array is appearing like this in Output, using NSLog()..



        
4条回答
  •  长情又很酷
    2021-01-24 15:09

    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];
    }
    

提交回复
热议问题