IOS 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: URLString'
转载自:http://i.cnblogs.com/EditPosts.aspx?postid=4012011
今天想写一个请求的天气,好的,废话不多说,先贴代码:
使用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:]; //获取城市
NSString *currentCity= [cityDict objectForKey:@"currentCity"];
//准备获取天气
NSArray *weatherArray= [cityDict objectForKey:@"weather_data"];
//获取第一天天气的字典
NSDictionary *firstDict=[weatherArray objectAtIndex:];
//获取第一天日期
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 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: URLString'的更多相关文章
- iOS 9 地图定位崩溃 n: 'Invalid parameter not satisfying: !stayUp || CLClientIsBackgroundable(internal->fClient)'
报错详情: *** Assertion failure in -[CLLocationManager setAllowsBackgroundLocationUpdates:], /BuildRoot/ ...
- 'Invalid parameter not satisfying: body'
afnetwork图片上传的时候出错,出现错误 2015-11-09 15:47:59.086 videoPro[3207:132795] *** Assertion failure in -[AFS ...
- iOS文件上传文件URL错误Invalid parameter not satisfying: fileURL'
一:iOS文件上传提示URL错误 Invalid parameter not satisfying: fileURL' 二:解决方法: NSString *imagePath = [[NSBundle ...
- 安装yii2时出错 Invalid Parameter – yii\base\InvalidParamException
最近composer安装yii2的时候页面报了这个错,应该是bower的前端资源位置改变的缘故! Invalid Parameter – yii\base\InvalidParamException ...
- Oracle 记录插入时“Invalid parameter binding ”错误
出现这种错误的原因可能有一下几种: 由于OracleParameter[] parameters:中parameters的个数和对应的插入SQL语句中的冒号个数不等: 参数个数和冒号个数相等,但是如下 ...
- 关于ImageMagick出现无效参数(invalid parameter)的解决方法
Windows 命令行 运行"convert logo.jpg f:\parseWord\tmp\logo.png" 时显示 “无效参数(Invalid Parameter)” ...
- java.sql.SQLException: Invalid parameter object type. Expected 'java.util.Map' but found 'java.lang.String 转载
java.sql.SQLException: Invalid parameter object type. Expected 'java.util.Map' but found 'java.lang. ...
- Failed to set MokListRT: Invalid Parameter Something as gone seriously wrong: import_mok_state() failed: Invalid Parameter
今天yum update升级centos7,重启后发现开不了机,报错如下: Failed to set MokListRT: Invalid ParameterSomething as gone se ...
- Vue微信自定义分享时安卓系统config:ok,ios系统config:invalid signature签名错误,或者安卓和ios二次分享时均config:ok但是分享无效的解决办法
简述需求:要求指定页面可以进行微信自定义分享(自定义标题,描述,图片,链接),剩下的页面隐藏所有基础接口.二次分享依然可以正常使用,切换至其他页面也可以正常进行自定义分享. 这两天在做微信自定义分享的 ...
随机推荐
- 通过 SignalR 类库,实现 ASP.NET MVC 的实时通信
在本文中,您将学到在现有 ASP.NET MVC 框架的 CRUD 项目中,如何使用 SignalR 类库,显示来自数据库的实时更新.在这一主题中,我们将重点放在在现有 ASP.NET MVC 框架的 ...
- php smarty foreach循环注意
在template中,要注意{foreach from=$arr item=value}其中的value不需要$美元符号
- 如何让Activiti-Explorer使用sql server数据库
从官网下载的Activiti-explorer的war文件内部默认是使用h2内存数据库的,如果想改用其他的数据库来做持久化,比如sql server,需要做如下配置. 1)修改db.propertie ...
- asp.net将sql语句封装在类库中
将sql语句封装在cs中,通过类库的引用使用他的select.update.insert 源代码(cs): using System; using System.Collections.Generic ...
- [codility]Falling-discs
http://codility.com/demo/take-sample-test/omega2013 这题有点意思.首先经过思考,想到从底部往上扫,去迎接掉下来的disc.但这样仍然是不行的.后来看 ...
- Java集合类之Hashtable
package com.test; import java.util.*; public class Demo7_3 { public static void main(String[] args) ...
- 【HDOJ】2102 A计划
BFS,不过有很多地方需要注意,比如传送机传送到另一个传送机.还有要注意格式. #include <iostream> #include <cstdio> #include & ...
- 坑爹的libxml2 for mingw 编译 (二)
makefile 中由于大量使用了cmd /C ""样式去执行mkdir和copy操作,导致mingw最后出错,因为会从mingw切换至cmd界面.因此需要把相关代码进行修改. # ...
- Eclipse设置、问题解决方案
Eclipse设置: 1.如何把eclipse关闭提示调出来? 可以这样打开这个提示:选择 Windows --Preferences,在左边树上选择“General” --“Startup and ...
- ArchLinux安装开源VMware Tools
首先按照传统的Linux下安装VMware Tools的方法[1]]出现了很多的错误,安装过程完全没有办法进行下去.我在ArchLinux Wiki中看到这样一句说:VMware Tools for ...