我正在嘗試使用AFNetworking檢索一些JSON數據。使用AFNetworking檢索JSON問題
我的服務器組件(PHP/ZendFramework)提供了以下回應:
>curl -i http://test.local:8080/public/appapi/testaction/format/json
HTTP/1.1 200 OK
Date: Mon, 06 Feb 2012 10:37:20 GMT
Server: Apache
X-Powered-By: PHP/5.3.8
Content-Length: 35
Content-Type: application/json
{"entries":"test","abcxxx":"test2"}
我嘗試使用下面的代碼來獲取這些JSON數據:
NSString *baseurl = @"http://test.local:8080";
NSString *path = @"/public/appapi/testaction/format/json";
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:baseurl]];
[client registerHTTPOperationClass:[AFJSONRequestOperation class]];
[client setAuthorizationHeaderWithUsername:@"myusername" password:@"mypassword"];
[client getPath:path parameters:nil success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
//NSLog(@"sjson: %@", [JSON valueForKeyPath:@"entries"]);
NSLog(@"sjson: %@", JSON);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error Code: %i - %@",[error code], [error localizedDescription]);
}];
當在模擬器上運行控制檯顯示以下輸出:
2012-02-06 11:22:39.800 App[3642:15803] sjson: <6a736f6e 466c6963 6b724170 69287b22 6d657468 6f64223a 7b225f63 6f6e7465 6e74223a 22666c69 636b722e 74657374 2e656368 6f227d2c 2022666f 726d6174 223a7b22 5f636f6e 74656e74 223a226a 736f6e22 7d2c2022 6170695f 6b657922 3a7b225f 636f6e74 656e7422 3a223336 32306666 32343265 37323336 34633135 32373031 31353438 62393335 3066227d 2c202273 74617422 3a226f6b 227d29>
任何暗示我在做什麼wr ong將不勝感激:)我試圖訪問Twitter API,並且工作完全正常...
你如何解決這個問題?有數據? – 2014-02-26 17:26:14