From my backend API, I get a json of objects consisting of array, dictionary, number, bool, string etc. For eg.
{
data:[
{
id : 1,
name : "abcd"
},
{
id : 2,
name : "abcde"
},
{
id : 3,
name : "abcde"
},
]
total_count : 10
}
Sometimes the value in total_count comes as a number and sometimes it comes as a string. In my code I have coded
[lbl setText:[jsonObject valueForKey:@"total_count"]]
This crashes because when the total_count key value is a number. Obviously I can do this
[lbl setText:[NSString stringWithFormat:@"%d",[[jsonObject valueForKey:@"total_count"] intValue]]];
but this happens at a lot of places in the API. A string is coming instead of a bool.
data:false
instead of data:[]
[EDIT]
[[AFHTTPRequestOperationManager manager] GET:[URLString attachToken] parameters:parameters success:^(AFHTTPRequestOperation * _Nonnull operation, id _Nonnull responseObject) {
if([[[responseObject valueForKey:@"response"] valueForKey:@"status"] boolValue]) {
NSLog(@"success");
}
if(success)success(operation, **responseObject**);
} failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * _Nonnull error) {
if(failure)failure(operation, error);
if(operation.response.statusCode == 0) {
ATAFNetworkingRequestObject *obj = [[ATAFNetworkingRequestObject alloc] init];
obj.urlString = URLString;
obj.paramters = parameters;
obj.successBlock = success;
obj.failureBlock = failure;
obj.type = ATNetworkingRequestGET;
if(![self duplicateRequestExists:obj])[pendingAPICalls addObject:obj];
}
[self logAPIFailedWithOperation:operation parameters:parameters error:error];
} autoRetry:5 retryInterval:7];