我试图用Xcode 7.3.1、iOS 9.3和JSON将天气数据解析到我的应用程序中,方法是使用天气地下API (但其他API(如OpenWeatherMap)也有同样的问题)。
当我构建我的应用程序时,我不会出错,但是当我在模拟器中调用天气时,我会得到一个"Thread 1: signal SIGABRT“错误。我使用断点来推测我的问题来自于序列化。
我已经试过清理我的项目,我没有双重连接。
当我下载并运行这教程项目时,我也遇到了同样的问题.
这是我的代码:
#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
我的错误窗口:
这里
谢谢您的帮助,为我的英语感到抱歉,我是法国人!
发布于 2016-07-29 18:24:42
https://stackoverflow.com/questions/38661872
复制相似问题