0

I have got json response and i have to display only those data which status = 1 so how can i do this please help me

my response is

JSON: (
        {
        name = "Kate Bell";
        phone = "(555) 564-8583";
        status = 0;
    },
        {
        name = "Daniel Higgins";
        phone = "(408) 555-5270";
        status = 0;
    },
        {
        name = "John Appleseed";
        phone = "888-555-5512";
        status = 0;
    },
        {
        name = "Anna Haro";
        phone = "<null>";
        status = 1;
    },
        {
        name = "Hank Zakroff";
        phone = "<null>";
        status = 1;
    },
 }
Birendra
  • 623
  • 1
  • 5
  • 17

2 Answers2

1

use predicate to get filtered array with status 1

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"status = %d", 1]; 
NSArray *arrFilter = [YourWholeArray filteredArrayUsingPredicate:predicate];
NSLog(@"array with status 1 ->%@",arrFilter);
Bhavin Bhadani
  • 22,224
  • 10
  • 78
  • 108
1

with that assumption, your JSON response start with array

If you really need the string of the JSON, it's available by looking at operation.responseString.

I take the answer from here

responseObject is either an NSArray or NSDictionary. You can check at runtime using isKindOfClass::

if ([responseObject isKindOfClass:[NSArray class]]) {
    NSArray *responseArray = responseObject;
    /* do something with responseArray */
     NSPredicate *predi = [NSPredicate predicateWithFormat:@"status = 1"]; 
NSArray *newarray = [responseArray filteredArrayUsingPredicate:predi];


} else if ([responseObject isKindOfClass:[NSDictionary class]]) {
    NSDictionary *responseDict = responseObject;
    /* do something with responseDict */

     NSArray *responseArray = responseDict[@"yourrootKeyname"];

     NSPredicate *predi = [NSPredicate predicateWithFormat:@"status = 1"]; 
NSArray *newarray = [responseArray filteredArrayUsingPredicate:predi];
}
Community
  • 1
  • 1
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143