AFNet 例子

来源:互联网 发布:搭建数据库服务器 编辑:程序博客网 时间:2024/05/17 06:35

  NSMutableURLRequest *request = [self.hfClientrequestWithMethod:@"GET"path:

                                    @"http://9snow.org/weather/api?city=%E5%8C%97%E4%BA%AC"

                                                  parameters:nil];

    [request setTimeoutInterval:30];

    //

    [AFJSONRequestOperationaddAcceptableContentTypes:[NSSetsetWithObject:@"text/html"]];

    

    AFJSONRequestOperation *operation = [AFJSONRequestOperationJSONRequestOperationWithRequest:request success:^(NSURLRequest *request,NSHTTPURLResponse *response, id JSON)

                                         {

                                             NSLog(@"json %@",[JSONclass]);

                                             _resultTextView.text = [NSStringstringWithFormat:@"%@",JSON];

                                             // do something with return data

                                         }failure:^(NSURLRequest *request,NSHTTPURLResponse *response, NSError *error,id JSON)

                                         {

                                             // code for failed request goes here

                                             NSLog(@"%@",[errordescription]);

                                             _resultTextView.text = [NSStringstringWithFormat:@"%@",JSON];


                                         }];

    operation.JSONReadingOptions =NSJSONReadingAllowFragments;

    [operation start];


原创粉丝点击