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=%@",@"XXXXXXX",@"3225"];
NSLog(@"%@",parameterString);
[request setHTTPMethod"OST"];
[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);
这是我的 json 解析,我的问题是当我点击这个 api 时它正在显示
{
message = "Valid skey required.";
status = 0;
}
但是这个 api 在 safari 中工作。我认为问题是请求添加到 url 错误。你能帮我吗....
Best Answer-推荐答案 strong>
我通过 AFNetworking 3 得到响应
试试这个
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) {
}];
关于ios - Json 代码不起作用,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/40839384/
|