我在我的服务器端有一个 Action :
public void Action(Container container)
{
}
容器在哪里:
public class Container
{
public string[] Arr;
}
从客户端,我通过以下方式调用此操作:
$.post("Controller/Action", { Arr: "abc" }, null, "json");
在此之后,容器中的Arr包含一个元素“abc”。
但是,在以下面的方式调用操作时:
$.post("Controller/Action", { Arr: ["abc", "def"] }, null, "json");
json 数组没有在服务器端反序列化。容器中的 Arr 为 NULL。
如何让这个简单的东西发挥作用?
问候
最佳答案
如果你使用的是 jquery 1.4,试试这个:
$.ajax({
url: 'Controller/Action',
type: 'post',
data: { Arr: [ 'abc', 'def' ] },
traditional: true,
dataType: 'json'
});
注意 traditional
flag .
或者如果您希望继续使用 $.post()
:
$.post(
'Controller/Action',
$.param({ Arr: [ 'abc', 'def'] }, true),
null,
'json'
);
关于c# - 如何让json数组解析在服务端工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3823919/