1. 程式人生 > >AFNnetworking請求json資料

AFNnetworking請求json資料

 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSString * post_url =[ServerIP stringByAppendingString:getPngURL];
    manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:[NSSet setWithObjects:@"application/json",@"text/json",@"text/javascript",@"text/html",nil]];
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    manager.securityPolicy.allowInvalidCertificates = YES;
    NSMutableDictionary *parameters=[[NSMutableDictionary alloc] init];
    [parameters setObject:version forKey:@"version"];
    [parameters setObject:@"ios" forKey:@"mobileType"];
    [manager GET:post_url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
      
        NSString *requestTmp = [NSString stringWithString:operation.responseString];
        NSData *resData = [[NSData alloc] initWithData:[requestTmp dataUsingEncoding:NSUTF8StringEncoding]];
        //系統自帶JSON解析
        NSDictionary *mydict  = [NSJSONSerialization JSONObjectWithData:resData options:NSJSONReadingMutableLeaves error:nil];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

       
    }];