[英]2D Array angularjs to c#
我可以从这样的角度控制器中调用ac#方法:
angualarjs:
$http.post('myC#Function', { "input": input )
.success(function (response) {
console.log("success send response: " + response);
})
.error(function (response) {
console("error send response: " + response);
});
C#
public string myC#Function(string input)
{
return "success";
}
当我尝试将2D数组从angular传递到c#控制器时,就会出现我的问题:
angularjs:
var my2DArray= [[], []];
// array is populated here (not shown)
$http.post('myC#Function', { "inputArray": my2DArray)
.success(function (response) {
console.log("success send response: " + response);
})
.error(function (response) {
console("error send response: " + response);
});
C#
public string myC#Function(string[,]input)
{
return "success";
}
任何帮助将被申请。
使用Newtonsoft Json库(必须已经在您的项目中)。
public string YourCSharpFunction(string yourJson2DArrayFromAngular)
{
var your2DArrayInCSharp = JsonConvert.DeserializeObject<string[,]>(yourJson2DArrayFromAngular);
return "success";
}
使用JSON.stringify
发送数据
$http.post('myC#Function', { JSON.stringify({ input : input }) })
和C#函数签名为
public string myC#Function(string[][] input) {}
您应该在post header
添加contentType: "application/json; charset=UTF-8"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.