2016-07-29 45 views
1

我試圖通過使用Weather Underground API解析天氣數據到我的應用程序與Xcode 7.3.1,iOS 9.3和JSON(但我遇到了與其他API相同的問題如OpenWeatherMap)。JSON序列化「線程1:信號SIGABRT」錯誤

我在構建應用程序時沒有遇到錯誤,但當我在模擬器中調用天氣時,出現「線程1:信號SIGABRT」錯誤。我用斷點來推測我的問題來自序列化。

我已經嘗試清理我的項目,我沒有雙重連接。

當我下載並運行this教程的項目,我有同樣的問題...

這裏是我的代碼:

#import "ViewController.h" 

@interface ViewController() 

@property (weak, nonatomic) IBOutlet UIButton *affichermeteo; 
@property (weak, nonatomic) IBOutlet UILabel *meteo; 

@end 



@implementation ViewController 


- (void)viewDidLoad { 
    [super viewDidLoad]; 


} 

- (IBAction)affichermeteo:(id)sender { 

NSData *allCoursesData = [[NSData alloc] initWithContentsOfURL: 
           [NSURL  URLWithString:@"http://api.wunderground.com/api/e5cdee14984e242b/conditions/q/CA/San_Francisco.json"]]; 

NSError *error; 

NSDictionary *allCourses = [NSJSONSerialization 
          JSONObjectWithData:allCoursesData 
          options:NSJSONReadingMutableContainers 
          error:&error]; 



if(error) 
{ 
    NSLog(@"%@", [error localizedDescription]); 
} 
else { 
    NSArray *currentobservation = allCourses[@"estimated"]; 
    for (NSDictionary *theCourse in currentobservation) 
    { 
     _meteo.text=theCourse[@"weather"]; 

    } 
} 



} 



@end 

我的錯誤窗口:

Here

非常感謝您的幫助和對我的英語感到抱歉,我是法語!

+0

哪條線路崩潰?你可以編輯你的問題,從崩潰中添加堆棧跟蹤? (您可能需要設置異常斷點,以便確定導致崩潰的行。) –

+0

崩潰顯示在「options:NSJSONReadingMutableContainers」行中。 – Jeremy

+0

這表明服務器正在給你形成嚴重的JSON。你可以將內容提供給不同的JSON解析器或JSON驗證器嗎? –

回答

0

我能夠使用您的代碼獲取數據。您錯過了iOS 9新添加的App Transport Security標誌。

添加應用交通運輸安全設置密鑰和標記允許任意負載YES像下面的截圖:

enter image description here

這應該解決您的問題。

查詢this鏈接瞭解有關App Transport Security的更多信息。

+0

非常感謝!這解決了我的問題! – Jeremy