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 ?
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;
}
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] dynamic dynObject){
if(dynObject.Type == "Array") {
// Handle list
}
// Handle response
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.