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

后端 未结 4 429
广开言路
广开言路 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 14:59

    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 !!!!!

    0 讨论(0)
  • 2021-01-24 15:01

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

    0 讨论(0)
  • 2021-01-24 15:08
    [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

    0 讨论(0)
  • 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];
    }
    
    0 讨论(0)
提交回复
热议问题