gpt4 book ai didi

ios - NSArray 创建的 NSArray

转载 作者:行者123 更新时间:2023-11-29 03:29:06 27 4
gpt4 key购买 nike

在我的应用程序中,我必须创建这样的结构:

$arrProducts = array(
array(
“product_id” => “1”,
“qty” => 2
"options" => array(
optionId_1 => optionValue_1,
...,
optionId_n => optionValue_n
)

我做了这个数组数组:

NSDictionary *dict = @{
@"product_id" : productID,
@"qty": self.qty
};
NSArray *array2 = @[dict];

这个数组应该可以与 Magento 商店一起使用,当我运行该应用程序时,它会向我显示这条消息:

错误 cart_product.add:SQLSTATE[21000]:违反基数:1241 操作数应包含 1 列

我想这个问题,取决于我如何创建这个数组,但我不明白这个数组有什么问题,你能帮我解决吗?

更新:

我用来连接到 Magento 的库需要这个结构:

[Magento call:@[@"customer.create", @{
@"email": email,
@"password": password,
@"firstname": firstname,
@"lastname": lastname,
@"website_id": @1,
@"store_id": Magento.service.storeID
}] success:^(AFHTTPRequestOperation *operation, id responseObject) {
Magento.service.customerID = responseObject;
NSLog(@"signUp customerID = %@", Magento.service.customerID);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error %@", error.localizedDescription);
}];

如果您查看 Magento SOAP API to add a product to cart,我将使用它来将产品添加到购物车中您可以看到,在 php 中,他们使用数组的数组来添加产品。我需要复制相同的结构。

最佳答案

首先,将 NSDictionary 放入数组中,然后再次执行此操作。那是错误的。这样做:

NSDictionary *product1 = @{@"product_id" : productID, @"qty": self.qty, "options" : @{optionId_n : optionValue_n}};
NSDictionary *product2 = @{@"product_id" : productID, @"qty": self.qty, "options" : @{optionId_n : optionValue_n}};
NSArray *products = @[product1, product2];

关于ios - NSArray 创建的 NSArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20045348/

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