2013-03-26 37 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