Search code examples
iosobjective-cjsonnsarray

How to remove a JSON objectForKey which is different throughout the NSArray?


I have following response of filtered array 2

    if(requestType == RequestTypeGetReportMaterialStatus)
            {
                materialStatusArray=response[@"customerstatus"];
                NSLog(@"Filtered Array2%@",materialStatusArray);
}

1 =     {
    bookingid = 469;
    status = 1;
};
2 =     {
    bookingid = 493;
    status = 1;
};
3 =     {
    bookingid = 486;
    status = 1;
};
4 =     {
    bookingid = 501;
    status = 1;
};
5 =     {
    bookingid = 506;
    status = 1;
};

But I want to a response to stored in a array which gives the following out put by cutting the numbers

   {

    bookingid = 469;

    status = 1;

};

   {

    bookingid = 493;

    status = 1;

};

   {

    bookingid = 486;

    status = 1;

};

     {

    bookingid = 501;

    status = 1;

};

    {

    bookingid = 506;

    status = 1;

};

How can I get the above format of array response to access the bookingid and status values for a comparision purpose... Please help me out by giving code snippet according to my response.

Thanks in Advance.


Solution

  • I guess the materialStatusArray is a NSDictionary actually, the array could be converted like:

    NSMutableArray *arrayWithoutNumbers = [NSMutableArray array];
    
    if ([materialStatusArray isKindOfClass:[NSDictionary class]]) {
        NSDictionary *dict = (NSDictionary *)materialStatusArray;
        [dict enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
            [arrayWithoutNumbers addObject:obj];
        }]
    }