网络解析是相当重要的知识点,我(ˇˍˇ) 想~网络时代不懂解析很多工作都无法展开了吧~~~
下面是我做的网络解析的测试
.h文件里的代码
#import <UIKit/UIKit.h>
@interface ViewController :UIViewController<NSURLConnectionDataDelegate>//“签订”异步连接的协议
//声明接收网络数据的属性
@property (retain ,nonatomic)NSMutableData * getData;//记得接收网络数据的数据类型得是可变的,否则为无法接收数据
@end
.m文件里的代码
#import "ViewController.h"
#import "JSON.h"//导入JSON解析的头文件
@interface ViewController ()
@end
@implementation ViewController
//——————————————————————————————异步连接
- (void)downLoad
{
//创建网络连接的路径
NSURL * urlDoc = [NSURLURLWithString:@"http://api.jiepang.com/v1/locations/search?lat=39.916&lon=116.393&count=2&source=100000"];
//请求路径的响应
NSURLRequest * requestUrl = [NSURLRequestrequestWithURL:urlDoc];
//以对象自身为代理,异步连接下载数据
[NSURLConnectionconnectionWithRequest:requestUrl delegate: