2016-07-29 47 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