My Json response data is,
[{"user_id":697,"provider":"Manual","user_image":"dummy_image.png"}]
The JSONModel extended class looks like,
@interface CILoginModel : JSONModel
@property (assign, nonatomic)int user_id;
@property (strong, nonatomic)NSString *provider;
@property (strong, nonatomic)NSString *user_image;
@end
And the code, which I used to assign the JSONResponse values automatically to the CILoginModel's objects is,
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//code executed in the background
//2
NSString *post = [NSString stringWithFormat:@"email=jil@yopmail.com&password=123456&provider=Manual"];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"URL GOES HERE"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSString *requestReply = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"requestReply: %@", requestReply);
NSError *dueError=nil;
CILoginModel* cilLogin = [[CILoginModel alloc] initWithString:requestReply error:&dueError];
NSLog(@"%@",cilLogin);
NSLog(@"%@",cilLogin.provider);
NSLog(@"%@",cilLogin.user_image);
}] resume];
});
But the problem is I always get null for cilLogin and its objects. I'm new to JSONModel and any help will be appreciated thanks!
