gpt4 book ai didi

iphone - NSInvalidArgumentException',原因: '-[__NSPlaceholderDictionary initWithObjects:forKeys: error

转载 作者:行者123 更新时间:2023-12-03 20:56:40 26 4
gpt4 key购买 nike

我正在使用 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>&lt;NewDataSet /&gt;</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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com