int x = 5;
int t = 6;
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:@"books.book", @"og:type",
@"www.goodreads.com", @"og:url",
@"Snow Crash", @"og:title",
@"978-3-16-148410-0",@"books:isbn",
@"http://en.wikipedia.org/wiki/File:Snowcrash.jpg", @"og:image",
@"www.google.com",@"og:audio:url",
@"www.facebook.com",@"al:windows_universal:url",
@"www.facebook.com",@"al:windows_phone:url",
@"www.facebook.com",@"al:windows:url",
@"www.facebook.com",@"al:iphone:url",
@"www.facebook.com",@"al:ipad:url",
x,@"books:rating:value",
t,@"books:rating:scale",
@"In reality, Hiro Protagonist delivers pizza for Uncle Enzo’s CosoNostra Pizza Inc., but in the Metaverse he’s a warrior prince. Plunging headlong into the enigma of a new computer virus that’s striking down hackers everywhere, he races along the neon-lit streets on a search-and-destroy mission for the shadowy virtual villain threatening to bring about infocalypse. Snow Crash is a mind-altering romp through a future America so bizarre, so outrageous…you’ll recognize it immediately.", @"og:description",
@"Chan Yee Choong", @"books:author",
@"Science Fiction",@"books:genre",
@"eu_es",@"books:language:locale",
@[@"en_us",@"ca_es",@"cs_cz"],@"books:language:alternate",nil];
正如您在上面所看到的,我试图创建一个词典,但每当我运行代码时,我都会得到这样的错误。
2014-06-11 23:50:50.338 TestApp[8374:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSDictionary dictionaryWithObjectsAndKeys:]: second object of each pair must be non-nil. Or, did you forget to nil-terminate your parameter list?'
*** First throw call stack:
(
0 CoreFoundation 0x00000001019ef495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010174e99e objc_exception_throw + 43
2 CoreFoundation 0x00000001019d27e3 +[NSDictionary dictionaryWithObjectsAndKeys:] + 1043
3 TestApp 0x000000010000724d -[CYCViewController postBooks:] + 1021
4 UIKit 0x00000001002fcf06 -[UIApplication sendAction:to:from:forEvent:] + 80
5 UIKit 0x00000001002fceb4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17
6 UIKit 0x00000001003d9880 -[UIControl _sendActionsForEvents:withEvent:] + 203
7 UIKit 0x00000001003d8dc0 -[UIControl touchesEnded:withEvent:] + 530
8 UIKit 0x0000000100333d05 -[UIWindow _sendTouchesForEvent:] + 701
9 UIKit 0x00000001003346e4 -[UIWindow sendEvent:] + 925
10 UIKit 0x000000010030c29a -[UIApplication sendEvent:] + 211
11 UIKit 0x00000001002f9aed _UIApplicationHandleEventQueue + 9579
12 CoreFoundation 0x000000010197ed21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
13 CoreFoundation 0x000000010197e5f2 __CFRunLoopDoSources0 + 242
14 CoreFoundation 0x000000010199a46f __CFRunLoopRun + 767
15 CoreFoundation 0x0000000101999d83 CFRunLoopRunSpecific + 467
16 GraphicsServices 0x0000000103b66f04 GSEventRunModal + 161
17 UIKit 0x00000001002fbe33 UIApplicationMain + 1010
18 TestApp 0x0000000100008153 main + 115
19 libdyld.dylib 0x00000001020875fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
我通过添加NIL来关注解决方案,但仍然无法正常工作。一切都很好。我检查了一下。
答案 0 :(得分:1)
字典中可以nil
的值为x
和t
。上述错误表明该对象不能nil
,您无法将nil
替换为字典中某个键的对象,而是可以尝试放置{{} 1}}甚至可以提供@""
。
<强>更新强>
正如你想要的那样
[NSNull null]
以上值是非对象值,字典需要对象,试试放。
int x = 5;
int t = 6;