jquery - How to deserialize JSON string received in controller -


i have received json string received in controller , unable deserialize it. please help. have attached jquery code , controller method in json string received. json received : "[\"account2\",\"account1\"][\"bcs\"][\"yes\"]"

image

$("#btn1").on("click", function ()         {             alert(j + " " + k);              $.ajax({                 type: 'post',                 url: '/todolist/searchdata',                 traditional: true,                 datatype:"json",                 data: "myarray1="+json.stringify(i) +json.stringify(j)+json.stringify(k),                 success: function (data)                 {                     alert(data);                 }             })          }); 

controller code:-

[httppost]         public jsonresult searchdata(string myarray1)         {              console.writeline(myarray1);            // console.writeline(myarray2);             javascriptserializer jsr=new javascriptserializer();             var data = jsr.deserialize<list<list<string>>>(myarray1);            console.writeline(data);             //using (sqlconnection connection = new sqlconnection("data source=.; database=srivatsava; integrated security=sspi"))             //{             //    dataset ds = new dataset();             //    connection.open();             //    sqlcommand cmd = connection.createcommand();             //    string str= "select accntname,bu,salesop,isdormant fourth_page fg"+             //                      " inner join linked ld on ld.productid=fg.productid"+             //                       "inner join isdormant on it.productid=ld.productid"+             //                       "where fg.accountname in(" + values+")";             //    cmd.commandtext = str;             //    sqldataadapter mysqldataadapter = new sqldataadapter();             //    mysqldataadapter.selectcommand = cmd;             //    mysqldataadapter.fill(ds);             //    foreach (datarow dr in ds.tables[0].rows)             //    {             //        console.writeline(dr[0].tostring() + "" + dr[1].tostring() + "" + convert.toint32(dr[2]) + "" + convert.toboolean(dr[3]));             //    }                             //    connection.close();             //}             return json(myarray1);          } 

you'll either want have controller receive object instead of string , pass

{ 'firstfield': i,   'secondfield': j,   'thirdfield': k } 

or try controller signature of

public jsonresult searchdata(list<string> firstfield, list<string> secondfield, list<string> thirdfield) 

and call appending following url instead of ajax post

"?firstfield=" + json.stringify(i) + "&secondfield=" + json.stringify(j) + "&thirdfield=" + json.stringify(k); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -