在httpclient中发送一个棘手的数组 [英] sending a tricky array in a httpclient
问题描述
我必须将数组中的数据集成到网络服务调用中,这并不是最有效的方法,但实际上就是如此.
I have to integrate data from an array into a webservice call which isn't the most efficient but it is what it is.
我有一个ID数组(朋友Facebook ID). 我需要在Titan的http客户端中将这些ID作为参数发送. 由于Titanium在通过Web服务传递数组时遇到了一些麻烦,因此我需要像这样构造http客户端的send方法:
I have an array of ids (friend facebook ids). I need to send these id's as parameters in a http client in titanium. Due to Titanium having some trouble with passing arrays in webservices, I need to construct the send method of my http client as such:
non_xhr.send('user_id=100005941351187&friend_ids[0]=100000049956179&friend_ids[1]=100005272411678');
显然,这取决于用户,他们将有不同数量的结果要存储在前面提到的(Facebook朋友ID)数组中.
Obviousy depending on the user, they will have a different number of results to be stored in the array previously mentioned (of facebook friend ids).
如上所述,我需要帮助如何基于上述数组的长度来集成循环,以构造所需的参数.
I need help in how to integrate a loop based on the length of array mentioned above in order to construct the parameters needed, as described above.
感谢所有帮助.
我正在使用Titanium,但是出于这个问题的目的,它基本上只是javascript
I am using Titanium but for the purposes of this question, it is basically just javascript
推荐答案
如何创建这样的参数:
function createParams(userId, friendIds) {
var output = "user_id=" + userId;
for(var i = 0, max = friendIds.length; i < max; i++) {
output += "&friend_ids[" + i + "]=" + friendIds[i];
}
return output;
}
您可以在此处找到可用的小提琴.
You can find a working fiddle here.
这篇关于在httpclient中发送一个棘手的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!