我正在为我的 iOS 应用程序使用用 PHP 开发的 Web 服务。现在我已经在 PHP 开发人员给出的 POST 正文中发送参数。但我无法以所需格式在 POST 正文中发送它。这是PHP开发人员给出的格式
Array
(
[key] => ecwrerwe3453453453454cea
[secret] => 45d77657657567jghjb6ef
[product] => Array
(
[name] => mobile
[id] => 3
[desc] => nokia c 5
[price] => 5
)
[spec] => Array
(
[0] => Array
(
[key] => color
[value] => ping
)
)
)
我发送到服务器的内容如下
{
key = c435435t3tergs680;
product = (
{
id= 3;
desc = "Test desc";
name = "Nokia mobile";
"price" = "987.65";
}
);
secret = 43ytehgrdghd1ee0d8;
specs = (
(
{
key = aaaaaaaaa;
value = aaaa;
}
),
(
{
key = bbbbbbbbbb;
value = bbbbb;
}
)
);
}
要在 POST 正文之上构建,我在 iOS 中使用以下代码
NSMutableArray *specsArray = [[NSMutableArray alloc]init];
for (ProductSpecification *prodSpecs in self.newProduct.specificationArray)
{
NSMutableDictionary *specsDict = [[NSMutableDictionary alloc]init];
[specsDict setValue:prodSpecs.name forKey:SPECS_NAME_KEY];
[specsDict setValue:prodSpecs.value forKey:SPECS_VALUE_KEY];
NSArray *array = [NSArray arrayWithObjects:specsDict, nil];
[specsArray addObject:array];
}
NSMutableArray *productArray = [[NSMutableArray alloc]init];
NSMutableDictionary *productDict = [[NSMutableDictionary alloc]init];
[productDict setValue:self.newProduct.name forKey:NAME_KEY];
[productDict setValue:self.newProduct.prodId forKey:ID_KEY];
[productDict setValue:self.newProduct.productDescription forKey:DESC_KEY];
[productDict setValue:self.newProduct.price forKey:PRICE_KEY];
[productArray addObject:productDict];
NSMutableDictionary *params = [[NSMutableDictionary alloc]initWithObjectsAndKeys:productArray,NEW_PRODUCT_ARRAY_NAME_KEY,specsArray,SPECS_ARRAY_KEY,nil];
// Get the API keys & append it in params
NSDictionary *keysDictionary = [kUserDefaults getAPIKeys];
[params setValue:[keysDictionary objectForKey:API_KEY] forKey:API_KEY];
[params setValue:[keysDictionary objectForKey:API_SECRET_KEY] forKey:API_SECRET_KEY];
NSLog(@"Params Dict: %@",params);
我无法将所需格式的数据发送到服务器。如何发送数组而不是 nsdictionary 中的键值?
谁能告诉我我的 iOS 代码出了什么问题?
任何形式的帮助都将受到高度赞赏。提前致谢。