gpt4 book ai didi

ios - '+[NSDictionary dictionaryWithObjectsAndKeys :]: second object of each pair must be non-nil. 或者,你是否忘记了 nil-terminate 你的参数列表?'

转载 作者:行者123 更新时间:2023-11-28 19:40:20 24 4
gpt4 key购买 nike

我将我的代码发布到 json 但我的应用程序错误

" 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?'"

-(void)requesdatesendorder:(NSArray *)foodid{
NSString *FoodId ;

for (int i =0; i < foodid.count; i++) {
NSString *idfood = [foodid objectAtIndex:i];
if (FoodId.length == 0) {
FoodId = [NSString stringWithFormat:@"%@,food_id[%d]",idfood,i];
}
else{
FoodId = [NSString stringWithFormat:@"%@,%@,food_id[%d]",FoodId,idfood,i];
}
}

NSLog(@"%@",FoodId);

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"date_send_order",@"params",
FoodId
,nil];
[self requestWithMethod:@"POST"
urlString:kFeedBeeservice
parameters:params
mode:Beeservicedatesendorder];
}

但我想发送json格式 http://i.stack.imgur.com/tkfqv.png

最佳答案

您还没有为 FoodId 指定任何键。您的 NSDictionary 语法错误。应该是这样的,

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"Object1",@"key1",@"object2",@"key2",nil];

在您的代码中为 FoodId 添加一个键或为 FoodId 添加一个对象。它将解决您的错误。

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"date_send_order",@"params",
FoodId,@"key",nil];

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"date_send_order",@"params",@"object"
FoodId,nil];

关于ios - '+[NSDictionary dictionaryWithObjectsAndKeys :]: second object of each pair must be non-nil. 或者,你是否忘记了 nil-terminate 你的参数列表?',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34673122/

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