Ios Json加速器和AFN网络
当操作运行时,我不能在加速器创建的JSON模型中输入数据。 你能告诉我我做错了什么吗Ios Json加速器和AFN网络,ios,json,afnetworking,Ios,Json,Afnetworking,当操作运行时,我不能在加速器创建的JSON模型中输入数据。 你能告诉我我做错了什么吗 { [super viewDidLoad]; NSLog(@"you are in a tableViewController"); self.title = @"NavigationOrdini"; NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.stampa6x3.com/js
{
[super viewDidLoad];
NSLog(@"you are in a tableViewController");
self.title = @"NavigationOrdini";
NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.stampa6x3.com/json.php?azione=ordini"]];
AFJSONRequestOperation* operation;
operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:req
success:^(NSURLRequest *request, NSURLResponse *response, id JSON)
{
[[ordiniModel alloc] initWithDictionary:JSON];
}
failure:^(NSURLRequest *request, NSURLResponse *response, NSError
*error, id JSON) {
[self setTitle:@"Dictionary"];
NSLog(@"failed! %d",[error code]);
}];
[operation start];
ordiniModel*test;
NSLog(@"il valore è %@",test.ordini.description);
}
AFJSONRequestOperation是异步的,这意味着当应用程序的其余部分运行时,代码将继续执行。完成块在代码实际完成时运行 因此,请尝试:
NSLog(@"you are in a tableViewController");
self.title = @"NavigationOrdini";
ordiniModel *test; // <-- create variable here
NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.stampa6x3.com/json.php?azione=ordini"]];
AFJSONRequestOperation* operation;
operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:req
success:^(NSURLRequest *request, NSURLResponse *response, id JSON)
{
test = [[ordiniModel alloc] initWithDictionary:JSON]; // <-- Assign here
NSLog(@"il valore è %@",test.ordini.description);
}
failure:^(NSURLRequest *request, NSURLResponse *response, NSError
*error, id JSON) {
[self setTitle:@"Dictionary"];
NSLog(@"failed! %d",[error code]);
}];
[operation start];
NSLog(@“您在tableViewController中”);
self.title=@“NavigationOrdini”;
OrdinModel*测试;//你能说得更具体些吗?你得到了什么样的回应?您是否收到错误?响应正常!无错误[test initWithDictionary:JSON]//