c# - Ajax + webservice + array of object -


i calling webservice through ajax call , pass array of object after stringify it.

data after stringifying

data = '[{"para1":"pic 1","para2":"drop 1"},{"para1":"pic 2","para2":"drop 2"}]'   $.ajax({         type: 'post',         url: "path url/method",         contenttype: "application/json; charset=utf-8",         datatype: "json",         data: json.stringify({             "data": data         }), 

how receive , parse in c# webservice.

    [webmethod]     [scriptmethod(responseformat = responseformat.json)]     public string insertroute(string data){        //how parse data here     } 

your service method receive data string. can use following code deserialize list of objects.

var serializer = new javascriptserializer(); var result = serializer.deserialize(mail, typeof(list<object>)); 

as practice, better if made model matches json object , passed typeof(list<model>)


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -