How to send dictionary with array using JSON? -


my fellow co-worker backend programmer said has configure api expect receive mobile app:

[{"id":50},{"id":60}] 

i'm using alamofire receive param dictionary sent. believe same mechanism using nsurlsession or other third party plugins.

the question is: how should construct dictionary send array of ids, how http form can have several text field same id, , received on server end array of id? i've tried far , fails:

param.setvalue(50, forkey:"id"); param.setvalue(60, forkey:"id"); // send last single value  param.setvalue([50, 60], forkey:"id"); // results in error (415 unsupported media type)  param.setvalue(50, forkey:"id[0]"); param.setvalue(60, forkey:"id[1]"); // results in error (415 unsupported media type) 

how can send correctly how web form send? thanks.

the problem first method you're overwriting value key id, that's reason why sends last value. try sending params array.

let dict = nsmutablearray() param.setvalue(50, forkey:"id") dict.addobject(param) param.setvalue(60, forkey:"id") dict.addobject(param) 

pass dict parameter request method.