IOS 'NSInternalInconsistencyException'

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

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



  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值