我正在研究一個iOS應用(對iOS很新穎),我有我的註冊流程工作,我發佈數據到我的服務器...服務器返回JSON,但我的問題是,我如何將它解析爲變量?從發佈請求ios afnetworking解析json
它返回的數據:
{"token":"67f41f60-9a9a-11e3-8310-11b6baf18c40","userId":13,"stationId":1}
我使用作出POST請求的代碼是:
[manager POST:@"http://localhost:3000/service/register_user/" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error!!!!!: %@", error);
}];
而且,當我提出發佈請求,這是什麼我得到的日誌在Xcode
2014-02-20 20:50:39.799 FlashoverResponse[4668:70b] Error!!!!!: Error Domain=AFNetworkingErrorDomain Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo=0x8a5e4f0 {NSErrorFailingURLKey=http://localhost:3000/service/register_user/, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x8a5e200> { URL: http://localhost:3000/service/register_user/ } { status code: 200, headers {
Connection = "keep-alive";
"Content-Length" = 74;
"Content-Type" = "text/html; charset=utf-8";
Date = "Fri, 21 Feb 2014 01:50:39 GMT";
"X-Powered-By" = Express;
}},NSLocalizedDescription =請求失敗:無法接受的內容類型:text/html的}
您的服務器需要使用內容類型「application/json」進行響應。任何現代的MVC或Web API框架將使這非常簡單。 –