AFJSONRequestSerializer

MoMo 2014-04-10

最近在做IOS的开发,网络请求采用了AFNetworking框架,由于服务器端是接收JSON的数据,新框架不太熟,网上搜了好久才解决,记录一下。

NSMutableDictionary*dict=[[NSMutableDictionaryalloc]init];

[dictsetObject:@"apple"forKey:@"brand"];NSString*url=@"http://xxxxx";//你的接口地址AFHTTPRequestOperationManager*manager=[AFHTTPRequestOperationManagermanager];

manager.responseSerializer=[AFJSONResponseSerializerserializer];//申明返回的结果是json类型

manager.responseSerializer.acceptableContentTypes=[NSSetsetWithObject:@"text/html"];//如果报接受类型不一致请替换一致text/html或别的

manager.requestSerializer=[AFJSONRequestSerializerserializer];//申明请求的数据是json类型

[managerPOST:urlparameters:dictsuccess:^(AFHTTPRequestOperation*operation,idresponseObject){

NSLog(@"%@",responseObject);

}failure:^(AFHTTPRequestOperation*operation,NSError*error){

NSLog(@"Error:%@",error);

}

];

相关推荐