2010-09-29 60 views
2

我有我的服務器端的操作JSON數組解析工作:如何使服務器端

public void Action(Container container) 
{ 
} 

,其中容器是:

public class Container 
{ 
    public string[] Arr; 
} 

從客戶端,我調用這個動作通過以下方式聯繫:

$.post("Controller/Action", { Arr: "abc" }, null, "json"); 

在此之後,編曲在續ainer包含一個元素「abc」。

但是,在調用動作通過以下方式:

$.post("Controller/Action", { Arr: ["abc", "def"] }, null, "json"); 

JSON數組不反序列化在服務器端。容器中的ArrNULL

如何使這個簡單的事情工作?

問候

回答

0

如果您使用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' 
);