Siva Sankar Siva Sankar - 10 days ago 6
iOS Question

Json Code is not working

NSString *urlString = @"http://chkdin.com/dev/api/peoplearoundmexy/?";
NSURL *url = [NSURL URLWithString:urlString];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

NSString *parameterString=[NSString stringWithFormat:@"skey=%@&user_id=%@",@"sa6rw9er7twefc9a7dvcxcheckedin",@"3225"];


NSLog(@"%@",parameterString);


[request setHTTPMethod:@"POST"];

[request setURL:url];

[request setValue:parameterString forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];


NSData *postData = [parameterString dataUsingEncoding:NSUTF8StringEncoding];

[request setHTTPBody:postData];

NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
NSLog(@"%@",[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]);
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(@"%@",dict);


This is my json parsing, my problem is when I am hit this api it is showing

{
message = "Valid skey required.";
status = 0;
}


But this api is working in safari.i am think is the problem is for request adding to url wrong. can you help me please....

Answer

i got response through AFNetworking 3

try this

 AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    [manager GET:@"http://chkdin.com/dev/api/peoplearoundmexy/?" parameters:@{@"skey":@"sa6rw9er7twefc9a7dvcxcheckedin",@"user_id":@"3225"} progress:nil success:^(NSURLSessionTask *task, id responseObject) {
        NSLog(@"%@",responseObject);
    } failure:^(NSURLSessionTask *operation, NSError *error) {
    }];

enter image description here