Balasubramanian Balasubramanian - 2 months ago 9
Objective-C Question

How to check the JSON format in objective c?

I will get the JSON Data like this. But I want to check whether key has an

Array
data or not. If It has 0 then skip. How can I check?

code = 200;
data = {
UserstoreReviewDetails = 0;
storeReviewDetails = 0;
}


or

code = 200;
data = {
UserstoreReviewDetails = (
{// array data}
);
storeReviewDetails = (
{// array data}
);
}


I have tried like this. But getting an exception if data has an
Array
value.

[[self.jsonValue[@"data"] objectForKey:@"storeReviewDetails"]intValue] != 0

[[self.jsonValue[@"data"] objectForKey:@"storeReviewDetails"] isEqualToString:@"0"]

Answer

// try like this

if([[[self.jsonValue[@"data"] objectForKey:@"storeReviewDetails"] isKindOfClass:[NSArray class]]) {
// data is array type
} else {
  //data is not an array type
}