-2

this is the json string that i am receiving from the API:

"incentives_and_benefits" = "{\"food\":{\"0\":\"\"},\"commission\":{\"0\":\"\"},\"uniform\":{\"0\":\"\"},\"transport\":{\"0\":\"\"},\"extras\":{\"0\":\"\"}}";

and i assigned it to dictionary. Now I need to get the values inside the dictionary. I tried using the solution given here: How to get values from dict

Heres what I have so far:

    NSString *strIncentives = [[self.jobDetailDict objectForKey:@"sub_slots"] objectForKey:@"incentives_and_benefits"];
    NSData *jsonData = [strIncentives dataUsingEncoding:NSUTF8StringEncoding];

    NSError *e;
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:nil error:&e];
    NSLog(@"DICT: %@", dict);

    NSString *food = [dict objectForKey:@"food"];
    NSLog(@"DICT: %@", food);
    NSString *commission = [dict objectForKey:@"commission"];
    NSLog(@"DICT: %@", commission);
    NSString *uniform = [dict objectForKey:@"uniform"];
    NSLog(@"DICT: %@", uniform);
    NSString *transport = [dict objectForKey:@"transport"];
    NSLog(@"DICT: %@", transport);
    NSString *extras = [dict objectForKey:@"extras"];
    NSLog(@"DICT: %@", extras);

Now I need to check whether food's value is 0 or 1..When Food's value is 1 then i need to get Hello string and display it. (this is just an example) food: {"1":"Hello"}

    if([food isEqualToString:@""])
    {
        //the string will be placed here
        NSLog(@"FOOD Available")
    }

when i reach the if statement i get an error:

[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance

How will i be able to resolve this? please help and thank you in advance.

Community
  • 1
  • 1
aianLee
  • 97
  • 1
  • 2
  • 11
  • possible duplicate of [How can I debug 'unrecognized selector sent to instance' error](http://stackoverflow.com/questions/25853947/how-can-i-debug-unrecognized-selector-sent-to-instance-error) – Hot Licks Feb 11 '15 at 03:10
  • possible duplicate of [How do I parse JSON with Objective-C](http://stackoverflow.com/questions/5547311/how-do-i-parse-json-with-objective-c) – Hot Licks Feb 11 '15 at 03:11
  • Go to json.org and learn the JSON syntax. It only takes 5-10 minutes to learn. – Hot Licks Feb 11 '15 at 03:12
  • possible duplicate of [How to parse JSON in iOS App](http://stackoverflow.com/questions/7530173/how-to-parse-json-in-ios-app) – Mayank Patel Feb 11 '15 at 03:19

1 Answers1

0
 if([[dict objectForKey:@"food"]isEqualToString:@“”]){
    NSLog(@"FOOD Available")
 }
Abhishek Sharma
  • 3,283
  • 1
  • 13
  • 22