c# - How to make json array parsing work on the server side -


i have action on server side:

public void action(container container) { } 

where container is:

public class container {    public string[] arr; } 

from client side, i'm invoking action in way below:

$.post("controller/action", { arr: "abc" }, null, "json"); 

after this, arr in container contains 1 element "abc".

but, while invoking action way below:

$.post("controller/action", { arr: ["abc", "def"] }, null, "json"); 

the json array not deserializing on server side. arr in container null.

how make simple thing work ?

regards

if using jquery 1.4 try this:

$.ajax({     url: 'controller/action',     type: 'post',     data: { arr: [ 'abc', 'def' ] },     traditional: true,     datatype: 'json' }); 

notice traditional flag.

or if prefer continue using $.post():

$.post(     'controller/action',      $.param({ arr: [ 'abc', 'def'] }, true),      null,      'json' ); 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -