IOS 'NSInternalInconsistencyException'
2017-06-17 21:19
495 查看
今天想写一个请求的天气。好的。废话不多说。先贴代码:
使用AFNetWorking 发送get请求,可是一直报错 IOS 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: URLString'
翻译出来就是 不能满足urlstring。 可能时请求地址错了。可是请求地址没错。返回是一串json数据。然后我就迷糊了,后来 我发现这个url中參数是直接写上去的
,然后parameters 放參数的地方 没放。后来我把參数单独写了进来。就搞定了啊。
正确代码:
这里的參数一定要写再 parameters 中,不然链接里的那些&符号。好像不识别把!
使用AFNetWorking 发送get请求,可是一直报错 IOS 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: URLString'
翻译出来就是 不能满足urlstring。 可能时请求地址错了。可是请求地址没错。返回是一串json数据。然后我就迷糊了,后来 我发现这个url中參数是直接写上去的
,然后parameters 放參数的地方 没放。后来我把參数单独写了进来。就搞定了啊。
[appDelegate.manager GET:@"http://api.map.baidu.com/telematics/v3/weather?location=南京&output=json&ak=4zG5R7SqnQa" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { NSDictionary *rootDict=responseObject; NSLog(@"%@",rootDict); NSArray *resultArray = [rootDict objectForKey:@"results"]; NSDictionary *cityDict=[resultArray objectAtIndex:0]; //获取城市 NSString *currentCity= [cityDict objectForKey:@"currentCity"]; //准备获取天气 NSArray *weatherArray= [cityDict objectForKey:@"weather_data"]; //获取第一天天气的字典 NSDictionary *firstDict=[weatherArray objectAtIndex:0]; //获取第一天日期 NSString *firstDate=[firstDict objectForKey:@"date"]; //获取第一天天气 NSString *weather=[firstDict objectForKey:@"weather"]; //获取第一天风向 NSString *wind=[firstDict objectForKey:@"wind"]; //获取第一天气温 NSString *temper=[firstDict objectForKey:@"temperature"]; [[[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"当前城市%@\n日期:%@\n天气%@\n风向%@\n气温%@\n",currentCity,firstDate,weather,wind,temper] message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"链接失败"); }]; });
正确代码:
NSDictionary *parameter=@{@"location": @"南京",@"output": @"json",@"ak": @"4zG5R7Lw8Fd3SqnQa"}; [appDelegate.manager GET:@"http://api.map.baidu.com/telematics/v3/weather" parameters:parameter success:^(AFHTTPRequestOperation *operation, id responseObject) {
这里的參数一定要写再 parameters 中,不然链接里的那些&符号。好像不识别把!
相关文章推荐
- IOS删除tableview'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in
- iOS之NSMutableDictionary导致程序崩溃:'NSInternalInconsistencyException'
- exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle解决办法
- Terminating app due to uncaught exception 'NSInternalInconsistency
- *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid
- Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArra
- Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableView
- * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '* -[NSCFArr
- "NSInternalInconsistencyException', reason: 'This NSPersistentStoreCoordinator has no persistent sto
- *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not
- uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of ro
- (xcode5.0 DEV target:iOS5.0) Could not find a storyboard named 'Main_iPhone.storyboard' in bundle,解决
- PHP操作RabbitMQ消息接收不到的问题【cannot publish to internal exchange 'push-apns' in vhost 'pushHost】
- (xcode5.0 DEV target:iOS5.0) Could not find a storyboard named 'Main_iPhone.storyboard' in bundle,解决
- X-code6 错误CodeSign error: code signing is required for product type 'Unit Test Bundle' in SDK 'iOS 8
- IPAD真机调试CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 8.0'
- iOS开发中的 @synthesize of 'weak' property is only allowed in
- Exception in thread "main" java.lang.InternalError: Can't connect to X11 window
- CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 5.0'
- 'Could not load NIB in bundle: 'NSBundle解决办法