Ash*_*ggs 1 json content-type ios afnetworking
我刚刚开始使用AFNetworking,但我似乎无法弄清楚如何让以下工作.
我的URL指向一个PHP文件,该文件将从数据库中检索的数据打印为JSON,但是使用AFNetworking我收到"预期内容类型"错误.
我的代码如下,但使用不同的URL.
NSURL *url = [NSURL URLWithString:@"http://www.example.com/json.php"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id json) {
NSLog(@"JSON: %@", [json valueForKeyPath:@"results"]);
} failure:nil];
[operation start];
Run Code Online (Sandbox Code Playgroud)
我想到了!:d
<?php header("Content-type: text/json"); ?>
Run Code Online (Sandbox Code Playgroud)
在屏幕上打印任何内容之前将其放在页面顶部,AFNetworking会将其识别为JSON
归档时间: |
|
查看次数: |
2315 次 |
最近记录: |