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
130k31 gold badges315 silver badges314 bronze badges
asked Jun 10, 2016 at 13:21
3
  • Is your request HttpPost? Commented Jun 10, 2016 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 ? Commented Jun 10, 2016 at 13:41
  • @SerdarToprak refer to this question stackoverflow.com/questions/1619302/… if you using Restful URLs with data in query string Commented Jun 10, 2016 at 15:51

1 Answer 1

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

answered Jun 10, 2016 at 13:48

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.