Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone NSInvalidArgumentException';,原因:'-[\uu NSPlaceholderDictionary initWithObjects:forKeys:错误_Iphone - Fatal编程技术网

Iphone NSInvalidArgumentException';,原因:'-[\uu NSPlaceholderDictionary initWithObjects:forKeys:错误

Iphone NSInvalidArgumentException';,原因:'-[\uu NSPlaceholderDictionary initWithObjects:forKeys:错误,iphone,Iphone,我正在使用NSMutableUrl请求从.net web服务器获取web数据 在获取数据之后,我使用soap请求获取数据,并通过使用NSXmlparsing解析响应将数据存储在NSDirectory中 我的代码是 NSArray *keys = [NSArray arrayWithObjects:@"id", @"firstname", @"lastname",@"addr",@"state",@"country",@"email",@"phone", nil]; directory =

我正在使用NSMutableUrl请求从.net web服务器获取web数据

在获取数据之后,我使用soap请求获取数据,并通过使用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)'
我从web服务器得到的响应如下

<?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>
NewDataSet/
然后应用程序退出

但若我得到了错误的响应,我如何才能识别,在那个时我需要显示一个警报,但不退出应用程序

我怎样才能做到这一点

我想我的问题很清楚

谁能帮我一下吗


提前感谢您。

假设
resultData
是一个
NSArray
,您可以测试
[resultData count]==8
您正在尝试创建一个字典并向它传递8个键(您的
变量),但您传递的值数不相等。事实上,Cocoa说您的
resultData
是一个空数组(甚至可能是零)。因此您需要使用以下内容来保护代码:

if ([resultData count] == 8) {
   // Creating the dictionary will succeed.
   directory = ... ;
} else {
   // Creating the dictionary will fail, handle or ignore that.
}