较老版本的 AFNetworking 下载链接 ( http://pan.baidu.com/s/14Cxga )
将压缩包中的文件夹拖入xcode工程项目中并引入如下的框架
简单的 JOSN
解析例子
static NSString *serverAddress =
@"http://m.weather.com.cn/data/101110101.html";
// 1.创建JSON操作对象
AFJSONRequestOperation
*operation =
[AFJSONRequestOperation
JSONRequestOperationWithRequest:[NSURLRequest requestWithURL:[NSURL
URLWithString:serverAddress]]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
{
NSLog(@"success --
%@", JSON);
} failure:^(NSURLRequest *request,
NSHTTPURLResponse *response, NSError *error, id JSON)
{
NSLog(@"failure --
%@", JSON);
}];
// 2.执行对象的操作异步加载
[operation start];
简单的 XML 解析例子
static NSString *serverAddress =
@"http://flash.weather.com.cn/wmaps/xml/beijing.xml";
// 1.创建XML操作对象
AFXMLRequestOperation *operation =
[AFXMLRequestOperation
XMLParserRequestOperationWithRequest:[NSURLRequest requestWithURL:[NSURL
URLWithString:serverAddress]]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser
*XMLParser) {
NSLog(@"success -- %@", XMLParser);
}
failure:^(NSURLRequest *request,
NSHTTPURLResponse *response, NSError *error, NSXMLParser *XMLParser)
{
NSLog(@"failure --
%@", XMLParser);
}];
// 2.执行对象的操作异步加载
[operation start];