我试图通过使用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
我的错误窗口:
非常感谢您的帮助和对我的英语感到抱歉,我是法语!
哪条线路崩溃?你可以编辑你的问题,从崩溃中添加堆栈跟踪? (您可能需要设置异常断点,以便确定导致崩溃的行。) –
崩溃显示在“options:NSJSONReadingMutableContainers”行中。 – Jeremy
这表明服务器正在给你形成严重的JSON。你可以将内容提供给不同的JSON解析器或JSON验证器吗? –