这是我的代码
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:]:
每对的第二个对象必须是非零的。或者,您是否忘记了终止参数列表?' ***首先抛出调用堆栈:
答案 0 :(得分:0)
在NSDictionary
或NSMutableDictionary
设置字符串值和字符串键。例:
以下示例格式正确,
[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"];
希望它有用