json解析2

JSON Accelerator(Json神器)


//把请求得来的数据data转化为string输出,将输出结果复制到JSON Accelerator(Json神器)中会工程文件夹里生成BaseClass和Parma的文件,将这四个文件拖入工程里即可


//请求数据

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);

//接收数据

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);

}

}];

你可能感兴趣的:(json解析2)