博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
IOS 'NSInternalInconsistencyException'
阅读量:4611 次
发布时间:2019-06-09

本文共 2057 字,大约阅读时间需要 6 分钟。

今天想写一个请求的天气。好的。废话不多说。先贴代码:

使用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 中,不然链接里的那些&符号。好像不识别把!

转载于:https://www.cnblogs.com/jhcelue/p/7041391.html

你可能感兴趣的文章
并不对劲的hdu4777
查看>>
linux使用rz、sz快速上传、下载文件
查看>>
判断数字的正则表达式
查看>>
DOC常用命令(转)
查看>>
php写一个判断是否有cookie的脚本
查看>>
Mac配置Fiddler抓包工具
查看>>
转:Java并发集合
查看>>
Word截图PNG,并压缩图片大小
查看>>
Python项目对接CAS方案
查看>>
mysql产生随机数
查看>>
编程风格
查看>>
熟悉常用的Linux命令
查看>>
易之 - 我是个大师(2014年3月6日)
查看>>
Delphi中窗体的事件
查看>>
file_get_contents()获取https出现这个错误Unable to find the wrapper “https” – did
查看>>
linux vi编辑器
查看>>
js树形结构-----(BST)二叉树增删查
查看>>
contract
查看>>
FJUT ACM 1899 Largest Rectangle in a Histogram
查看>>
如何删除xcode项目中不再使用的图片资源
查看>>