2016-11-27 80 views
0

沒有得到數據,而嘗試使用po data它說從Web服務

error: use of undeclared identifier 'data'
error: 1 errors parsing expression

-(void)viewWillAppear:(BOOL)animated { 
    NSMutableURLRequest*req=[[NSMutableURLRequest alloc]init]; 
    NSURL*url=[NSURL URLWithString:@"http://www.thomas-bayer.com/sqlrest/CUSTOMER/"]; 
    [req setURL:url]; 
    [[[NSURLSession sharedSession]dataTaskWithRequest:req completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { 
     if(error){ 
      NSLog(@"error"); 
     }else{} 
    }] resume]; 
} 
+0

實際上,數據是在'else'之後的大括號'{}'中返回的。如果你根本不使用它,你什麼都看不到。還要考慮到'URLSession'異步工作。 – vadian

回答

0

你在控制檯下面讓錯誤打印數據?

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file. 

我覺得你必須爲「http:」url配置App Transport Security Exception。

請看下面的問題來了解添加異常。

Transport security blocked

更新:

上面的網址給XML響應,請參閱以下鏈接XML解析

xml parsing in ios tutorial

+0

不......不是......我加入了plist。沒有得到數據和響應使用寶它說使用「​​寶數據」它說錯誤:使用未聲明的標識符'數據'錯誤:1錯誤解析表達式 – Nishanth

+0

我試過上面的代碼,並得到了一個XML響應。請使用NSXMLParser解析xml文件。 – Dili

+0

@Nishanth仍然收到空白的數據? – Dili

0

也許你可以在「其他設置斷點「分支。當數據返回時,它會觸發斷點,使用」po數據「。