- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 NSMutableUrl 请求从 .net Web 服务器获取 Web 数据。
在通过使用 NSXmlparsing 解析响应将我存储在 NSDirectory 中之后,我正在使用肥皂请求获取数据。
我的代码是
NSArray *keys = [NSArray arrayWithObjects:@"id", @"firstname", @"lastname",@"addr",@"state",@"country",@"email",@"phone", nil];
directory = [NSDictionary dictionaryWithObjects:resultData forKeys:keys];
[[NSUserDefaults standardUserDefaults] setObject:directory forKey:@"dictionaryKey"];
它工作正常,但每当我输入错误时,它就会出现这样的异常。
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSPlaceholderDictionary initWithObjects:forKeys:]: number of objects (0) not equal to number of keys (8)'
我从网络服务器收到这样的响应
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GenericAndroidMethodResponse xmlns="Mortgage"><GenericAndroidMethodResult><NewDataSet /></GenericAndroidMethodResult></GenericAndroidMethodResponse></soap:Body></soap:Envelope>
应用程序退出。
但是如果我得到错误的响应我该如何识别,当时我需要显示警报但不退出应用程序。
我怎样才能做到这一点。
我认为我的问题很清楚。
谁能帮帮我。
提前谢谢你。
最佳答案
您正在尝试创建一个字典并向其传递 8 个键(您的 keys
变量),但您没有传递相同数量的值。事实上,Cocoa 说你的 resultData
是一个空数组(甚至可能是 nil)。因此,您需要使用以下内容来保护您的代码:
if ([resultData count] == 8) {
// Creating the dictionary will succeed.
directory = ... ;
} else {
// Creating the dictionary will fail, handle or ignore that.
}
关于iphone - NSInvalidArgumentException',原因: '-[__NSPlaceholderDictionary initWithObjects:forKeys: error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4711510/
Swift 中的 CKRecord 类规范说明使用 setObject:forKey: 来设置 CKRecord 的值。但是我看到了很多带有 setValue:forKey: 的代码示例,它是 NSV
我使用 let userDefaults = UserDefaults.standard 设置了一些用户默认值,当我检索它们时,我可以使用以下任何一个: jobTextField.text = use
我正在尝试设置 NSMutableDictionary 深处的对象,我的意思是在我可以到达它们之前有几个级别的键。 显然我做不到 setObject:x forKey forKey forKey fo
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: Where's the difference between setObject:forKey: and s
在查看文档时,我几乎看不出有什么大的不同。 “值”和“对象”都是 id 类型,因此可以是任何对象。 Key 曾经是一个字符串,在另一种情况下是一个 id。其中一个似乎保留了该对象,而另一个则没有。还有
由于 forKey 的值是 NSString,我在 Apple 文档中哪里可以找到所有可能值的完整列表?谢谢 最佳答案 方法 addAnimation:forKey: 并没有按照您的想法进行操作。 第
由于UIView动画是由CAAnimation支持的,所以我猜,当id执行UIView animateWithDuration:animations时,CALayer的addAnimation:for
我确信我在尝试编写的一个简单 iPhone 程序中遗漏了一些明显的东西,但代码看起来非常基本,我看不出有什么问题。 我正在尝试使用 NSMutableDictionary 来存储类列表及其关联的保存文
如果我使用dictionaryWithObjects:forKeys:,并且我的键数组恰好有重复项,会发生什么?我认为重复键的最后一个实例将是与该键关联的值;这是正确的吗? 最佳答案 The docs
我在控制台中遇到此崩溃: 2011-08-27 23:26:45.041 App[1672:3117] *** Terminating app due to uncaught exception 'N
This question already has answers here: Swift equivalent to `[NSDictionary initWithObjects: forKeys:
在我的项目中,我创建了一个包含对象和键的字典我为对象和键创建 NSArray 但是当我尝试创建字典时它会发送以下错误: * Terminating app due to uncaught except
这个问题在这里已经有了答案: Sort array into dictionary (5 个答案) 关闭 7 年前。 我有一个名为 animals 的 NSMutableArray。我需要创建一个
我对(例如)UIView 上的setValue:forKey 方法有疑问。 我有以下代码: let label = UILabel() label.layoutMargins = UIEdgeInse
在更改某些 UILabel 的框架时,我有一个神秘的 EXC_BAD_ACCESS。崩溃是随机的,通常我必须重复几分钟的条件。 启用 NSZombies 以及其他内存调试标志(NSDebugEnabl
在 Swift 中不可能使用 .setValue(..., forKey: ...) Int 之类的可空类型字段? 具有 enum 类型的属性 可空对象数组,如 [MyObject?] 对此有一种解决
我尝试使用函数 -setValue:forKey: 并使用 -valueForKey: 获取值 示例: NSArray *rootarr = [[NSArray alloc] init]; NSArr
我很好奇下面的代码片段中的 setValue:forKey: 发生了什么:它只是将指针设置为指向每个数组,类似于... [self setMyArray_1: animalArray]; [self
我的代码给出了一个错误提示 No visible interface for 'NSMutableDictionary' declares the selector 'addObjects:forKe
轨迹是这样的 Application received signal SIGSEGV Stack trace: #0 CoreFoundation 002B
我是一名优秀的程序员,十分优秀!