1

I am very new to ios development, I am trying to add some values from NSMutableDictionary to NSMutableArray, when I run the code I get this error

2012-05-29 14:09:34.913 iShop[7464:f803] -[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x6e423d0 2012-05-29 14:09:34.915 iShop[7464:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x6e423d0' * First throw call stack: (0x13cb022 0x155ccd6 0x13cccbd 0x1331ed0 0x1331cb2 0x2bb7 0x13cce42 0x93b9df 0x139f94f 0x1302b43 0x1302424 0x1301d84 0x1301c9b 0x12b47d8 0x12b488a 0x15626 0x28bd 0x2825) terminate called throwing an exception(lldb)

below is my code:

-(void) getData:(NSData *) response {
    NSError *error;

    NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:response options:kNilOptions error:&error];
    //NSLog(@"%@", json);

    jsonArray = [[NSMutableArray alloc] init];

    jsonArray = [json objectForKey:@"Name"];

    NSLog(@"%@", jsonArray);

}

- (void)viewDidLoad {
    [super viewDidLoad];

    jsonURL = [NSURL URLWithString:@"http://localhost:8888/read_product_list.php"];
    dispatch_async(BgQueue, ^{
        NSData* data = [NSData dataWithContentsOfURL:jsonURL];
        [self performSelectorOnMainThread:@selector(getData:) 
                               withObject:data waitUntilDone:YES];
    });
}

1 Answer 1

2

JSONObjectWithData return an object of type id. depending on the structure of your received json data. The data recieved is eiher NSDictionary or NSArray. In your case I am guessing the top level object is of type NSArray which does not respond to objectForKey

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.