0

I have to take json list as parameter for web api.

http://localhost:8082/api/Values/EmptyCardList?number=[
{
    num: "1"
},
{
    num: "2"
},
{
    num: "3"
},
{
    num: "4"
},
{
    num: "5"
},
{
    num: "6"
},
{
    num: "7"
}
]

Is it possible ? Can it lead performance problem? Also parameter how much take character or list ?

Brian Rogers
  • 110,187
  • 27
  • 262
  • 261
Sezer Erdogan
  • 146
  • 1
  • 6
  • 29
  • Is your request HttpPost? – Pushpendra Jun 10 '16 at 13:30
  • yes.because I want to sent parameter json dataset in my service.After my service take this request and insert all data in my database.you can think as bulk insert.Is it possible ? or do you have any suggestion ? – Sezer Erdogan Jun 10 '16 at 13:41
  • @SerdarToprak refer to this question http://stackoverflow.com/questions/1619302/restful-urls-with-data-in-query-string-or-request-body if you using Restful URLs with data in query string – Amit Pore Jun 10 '16 at 15:51

1 Answers1

4

If you are making your httpPost request and passing json object in your request body

Set

contentType:"application/json"

and in data use JSON.stringify(yourJson);

Something like this:

    $(function () {
    var youJsondata = {num :"2",num:"3"};
    $.ajax({
        type: "POST",
        data :JSON.stringify(youJsondata),
        url: "http://localhost:8082/api/Values/emptycardlist",
        contentType: "application/json"
    });
});

You api method should look something like this:

[HttpPost]
Route("api/Values/emptycardlist")
public HttpResponseMessage EmptyCardList([FromBody] JObject jobject){
   dynamic numList = jobject;
}

Reference

Pushpendra
  • 1,644
  • 12
  • 26