gpt4 book ai didi

ios - Json 代码不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:26:47 24 4
gpt4 key购买 nike

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:@"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);

这是我的 json 解析,我的问题是当我点击它显示的这个 api 时

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

但是这个 api 在 safari 中工作。我认为问题是请求添加到 url 错误。你能帮帮我吗....

最佳答案

我通过 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) {
}];

enter image description here

关于ios - Json 代码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40839384/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com