public class JsonParamModel
{
/// <summary>
/// json key
/// </summary>
public string JsonKey {
get;
set; }
/// <summary>
/// json object
/// </summary>
public dynamic JsonObj {
get;
set; }
}
[HttpPost]
public Result WebapiDynamic(JsonParamModel json)
$.ajax({
type: "POST",
contentType: "application/json",
dataType: "json",
url: $("#url").val(),
data: JSON.stringify({"JsonKey":
"13",
"JsonObj": {
"Key1":
"11",
"Key2":
"-10" } }),
success: function (results) {
if (
typeof results ==
"object") {
JSON.stringify(results);
}
else {
var resultObj =
JSON.parse(results);
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.responseText);
}
});
总结:在实体或者直接在参数中采用dynamic可以动态的接收参数
但是ajax在调用的时候稍微有一点不同
data: JSON.stringify({"JsonKey": "13", "JsonObj": { "Key1": "11", "Key2": "-10" } }),
contentType: "application/json",
转载于:https://www.cnblogs.com/njcxwz/p/5925137.html
相关资源:JAVA上百实例源码以及开源项目