AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
// 所有的网络请求,均有manager发起
//需要注意的是,默认提交请求的数据是二进制的,返回格式是JSON
/*
AFHTTPRequestSerializer 二进制格式
AFJSONRequestSerializer JSON
AFPropertyListRequestSerializer PList(是一种特殊的XML,解析起来相对容易)
*/
//responseSerializer 接收数据类型
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
//如果报接受类型不一致请替换一致text/html或别的
//post 请求
//operation请求的数据?responseString返回的字符串?
[manager POST:GET_POST_INFO_URL parameters:nil success:^(AFHTTPRequestOperation *operation,id responSEObject) {
NSLog(@"Success:%@",responSEObject);
NSString* requestString=[NSString stringWithString:operation.responseString];
NSData* data=[[NSData alloc] initWithData:[requestString dataUsingEncoding:NSUTF8StringEncoding]];//返回的字符串转换成date
NSDictionary* jsonDict=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];//解析json为nsdictionary类型 数据会放在内存中
[data release];
_dataArray=[jsonDict objectForKey:@"data"];
FangYuanViewController* fangYuan=[[FangYuanViewController alloc] initWithNibName:@"FangYuanViewController" bundle:nil];
fangYuan.dataArray=[[[NSMutableArray alloc] init] autorelease];
fangYuan.dataArray=_dataArray;
[self addChildViewController:fangYuan];
[self.view addSubview:fangYuan.view];
[fangYuan didMoveToParentViewController:self];
[fangYuan release];
[ProgressHUD showSuccess:@"加载成功"];
NSLog(@"拿到房源数据成功");
} failure:^(AFHTTPRequestOperation *operation,NSError *error) {
[ProgressHUD showError:@"加载失败,请检查网路!"];
}];
@H_820_403@//
- (NSData
}
NSString
[jsonString
- (id)toArrayOrNSDictionary:(NSData
}
#import
@implementation
-(id)JSONValue;
{
}
@end
@implementation
-(NSData*)JSONString;
{
result = [NSJSONSerialization