2012-09-17 46 views
0

我需要將數組傳遞給webservice.I已將產品標識符存儲到nsmutablearray.and我想將此數組傳遞給我的PHP服務器。所以我有以下的事情。傳遞數組作爲後值ASIFormDataRequest

__block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; 
request.requestMethod = @"POST"; 
[request setPostValue:product_identifiers forKey:@"product_identifiers"]; 

當我的NSLog我的陣列,

(
     "com.hoiuat.test.loves.oneweek", 
     "com.hoiuat.test.loves.oneweek", 
     "com.hoiuat.test.loves.oneweek", 
     "com.hoiuat.test.loves.oneweek", 
     "com.hoiuat.test.loves.oneweek", 
     "com.hoiuat.4", 
     "com.hoiuat.11", 
     "com.hoiuat.3", 
     "com.hoiuat.8", 
     "com.hoiuat.6" 
    ) 

的PHP開發人員說,他們不能接收參數爲數組。

請讓我知道,我應該如何通過陣列。

+0

添加更多的代碼... – Ayaz

回答

0

這取決於什麼網絡服務需要,但你可以把它當作分隔爲一個字符串如下:

NSString *postValue = [product_identifiers componentsJoinedByString:@"&"]; 
NSString *postString = [NSString stringWithFormat:@"product_identifiers=%@, postValue]; 

// this will generate the string: 
// product_identifiers=com.hoiuat.test.loves.oneweek&com.hoiuat.test.loves.oneweek ... 

然後設置它的要求是這樣的:

[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];