JSON Accelerator(Json神器)
//把請求得來的數(shù)據(jù)data轉(zhuǎn)化為string輸出,將輸出結(jié)果復(fù)制到JSON Accelerator(Json神器)中會(huì)工程文件夾里生成BaseClass和Parma的文件,將這四個(gè)文件拖入工程里即可
//請求數(shù)據(jù)
NSURL* url = [NSURL URLWithString:@"http://localhost:8080/Login1/NewServlet?command=5"];
NSURLRequest * request = [[NSURLRequest alloc] initWithURL:url];
[NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *_Nullableresponse,NSData *_Nullabledata,NSError *_NullableconnectionError) {
NSString * str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"data -----%@",str);
//接收數(shù)據(jù)
NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
//接收字典
BaseClass * base = [BaseClassmodel ObjectWithDictionary:dic];
NSLog(@"----->%@",dic);
NSLog(@"--hgsygys8--->%@",base.parma);
//解析
for(Parma * parma in base.parma) {
NSLog(@"parma ---->%@",parma.name);
}
}];