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
-
Is your request HttpPost?Pushpendra– Pushpendra2016年06月10日 13:30:31 +00:00Commented 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 ?Sezer Erdogan– Sezer Erdogan2016年06月10日 13:41:07 +00:00Commented Jun 10, 2016 at 13:41
-
@SerdarToprak refer to this question stackoverflow.com/questions/1619302/… if you using Restful URLs with data in query stringAmit Pore– Amit Pore2016年06月10日 15:51:50 +00:00Commented Jun 10, 2016 at 15:51
1 Answer 1
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;
}
answered Jun 10, 2016 at 13:48
Comments
lang-cs