2013-03-26 55 views
0

当操作正在运行时,我无法在JSON模型CREATED BY ACCELERATOR中输入数据。 你能告诉我我做错了什么吗?Json加速器和AFNetworking

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

} 
+1

你能更具体?你作为回应得到什么?你有错误吗? – 2013-03-26 20:27:37

+0

回应没关系!没有错误 – 2013-03-26 20:29:54

回答

0

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]; 
+0

[test initWithDictionary:JSON]; // < - 错误是:表达式结果未使用 以及何时登录: NSLog(@“this is the revultate:%@”,[test description]); // < - - 当回想起这个方法时,值是:这是掠过:(null) – 2013-03-26 21:02:10

+0

它不起作用! :( – 2013-03-26 21:17:03