0
votes

I want to get the whatsapp number from JSON data which is in format as below

Json:" extra_values":"{\"whatsapp\":\"1234567890\",\"call\":\"+1234567890\"}"

    social_dict=[shop_info valueForKey:@"extra_values"];
    NSLog(@"%@",social_dict);//it_prints : {"whatsapp":"1234567890","call":"+1234567890"}


    NSLog(@"%@",[social_dict objectForKey:@"call"]);

    NSLog(@"%@",[social_dict objectForKey:@"whatsapp"]);

I am having problem in printing the whatsapp value.

Error: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x60400028bd10'

1
it prints {"whatsapp":"1234567890","call":"+1234567890"} so i think it means it is in dictionary.Sani mori
@Sunnymori You should convert Json string to NSDictionary value berofe using ittrungduc

1 Answers

1
votes

Try this

NSString *social_str = [shop_info valueForKey:@"extra_values"];

NSError *jsonError;
NSData *objectData = [social_str dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary * social_dict = [NSJSONSerialization JSONObjectWithData:objectData
                                      options:NSJSONReadingMutableContainers 
                                        error:&jsonError];

You are getting JSON string for extra_values so you have to convert it to NSDictionary by this