asp.net mvc - How to extract JSON data received in controller in a String variable -
could please let me know how extract json data received in string variable in controller. please see attachment.thanks.
$("#btn1").on("click", function () { var = new array(); var j = 0; $("#sl1").multiselect("getchecked").map(function () { alert(this.value); i.push(this.value); //i[j] = this.value; //j++; }).get(); var postdata = { values: }; jquery.ajaxsettings.traditional = true; $.post('/todolist/searchdata', postdata, function (data) { alert(data.result); }); //$.ajax({ // type: "post", // url: "/todolist/searchdata", // data: postdata, // success: function (data) { // alert(data.result); // }, // datatype: "json", // traditional: true //}); });
controller code:-
public void searchdata(string[] values) { //{ // javascriptserializer js = new javascriptserializer(); // list<string[][]> data=js.deserialize<list<string[][]>>(i); console.writeline(values); }
you can use newtonsoft json library https://www.nuget.org/packages/newtonsoft.json/
so mentioned in below link use below
string json = @"{ 'email': 'james@example.com', 'active': true, 'createddate': '2013-01-20t00:00:00z', 'roles': [ 'user', 'admin' ] }";
account account = jsonconvert.deserializeobject(json);
if doesn't have model , use below
var model = jsonconvert.deserializeobject(json);
the check below link
http://www.newtonsoft.com/json/help/html/deserializeobject.htm
Comments
Post a Comment