我正在研究一个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框架将使这非常简单。 –