每对的第二个对象必须是非零的。或者,您是否忘记了终止参数列表?'

时间:2016-05-11 09:00:15

标签: ios objective-c iphone json

这是我的代码

NSMutableArray * myArray = [[NSMutableArray alloc]init];

NSMutableDictionary * myData = [[NSMutableDictionary alloc]init];
[myData setValue:@"151" forKey:@"LoginID"];
[myData setValue:@"0" forKey:@"UserID"];
[myData setValue:@"0" forKey:@"SubUserID"];
[myData setValue:@"92" forKey:@"WorkGroupID"];
[myData setValue:@"Doctor" forKey:@"WorksFor"];
[myData setValue:@"0" forKey:@"UserWorkGroup"];

[myArray addObject:myData];

myData = [[NSMutableDictionary alloc]init];
[myData setValue:@"," forKey:@"SortingName"];
[myData setValue:@"1" forKey:@"Searching"];
[myData setValue:@"Desc" forKey:@"SortingOrder"];
[myData setValue:@"10" forKey:@"RecordsCount"];
[myData setValue:@"0" forKey:@"PageIndex"];
[myArray addObject:myData];

NSData *dataToSend = [NSJSONSerialization dataWithJSONObject:myArray options:0 error:nil];
NSString *jsonString = [[NSString alloc] initWithData:dataToSend encoding:NSUTF8StringEncoding];

[getProfileServices sendSynchronousPostRequestWithStringForAction:getProfileURL andParameters:[[NSDictionary alloc]initWithObjectsAndKeys:jsonString ,nil]andRequestType:@"POST"];

当我运行时遇到此错误

  

NSInvalidArgumentException,原因:-[__NSPlaceholderDictionary initWithObjectsAndKeys:]:每对的第二个对象必须是非零的。或者,您是否忘记了终止参数列表?'   ***首先抛出调用堆栈:

1 个答案:

答案 0 :(得分:0)

NSDictionaryNSMutableDictionary设置字符串值和字符串键。例: 以下示例格式正确,

[myData setValue:@“1”forKey:@“Searching”];

  

不发送nil值和nil键。

     

不要在字典

中发送内部值

你的错误在下面给出

[myData setValue:@"," forKey:@"SortingName"];

以上问题是“,”

更改代码如下,

[myData setValue:@"String Value" forKey:@"SortingName"];

请更改以下代码,

[getProfileServices sendSynchronousPostRequestWithStringForAction:getProfileURL andParameters:[[NSDictionary alloc] initWithObjectsAndKeys:dataToSend] andRequestType:@"POST"];

希望它有用