开发者

Send array of objects to RESTful API

开发者 https://www.devze.com 2023-03-29 06:40 出处:网络
How can I send an array (a set of simular items) in a POST request to a RESTful API build with Codeigniter?

How can I send an array (a set of simular items) in a POST request to a RESTful API build with Codeigniter?

I can开发者_开发问答 send singular items like this:

name=John&email=demo@demo.com

But how can I send items like this and use them on the server side like an array?

keywords=blue,sky,weather,car,vacation


I would think you could send a json array depending on the capabilities of the backend. If the RESTful API consumes this content type you are able to then send an array by simply POSTing to the RESTful path, using the json array as the payload.

One way to send the payload would be with jQuery / AJAX:

.ajax({
    url: "",
    type: "POST",
    contentType: "application/json",
    data: JSON.stringify(jsonArray)
});


is it possible to send it in JSON?

{"keywords" : ["blue","sky","weather","car","vacation"]}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号