javascript - how to access properties of json string -


i have json string coming database table has empty root element name

{"": [   {"id":18,"menuname":"dsadasdasd","isactive":"inactive"},   {"id":17,"menuname":"karachi","isactive":"active"},   {"id":2,"menuname":"user management","isactive":"active"},   {"id":1,"menuname":"home","isactive":"active"} ]} 

i trying access json below jquery ajax call method

function get_datatable() {     $.ajax({         url: "gridview_jqueryfunctionality.aspx/calldatatable_emptyrootname",         type: "post",         data: '{}',         contenttype: "application/json; charset=utf-8",         datatype: "json",         success: function (data) {             alert(data.d) // showing json fine             var mydata = $.parsejson(data.d);             (i = 0; < object.keys(mydata).length; i++) {                 alert(mydata[i].id + ' : ' + mydata[i].menuname);             }         }     }); } 

my webmethod

[webmethod(true)] public static string calldatatable_emptyrootname(){         list<category> categories = new list<category>();     clsmenu objmenu = new clsmenu();     datatable dt = new datatable();     objmenu.getallmenu(dt);     if (dt.rows.count > 0){         string jsonstring = conversionextension.datatabeltojson(dt);                     return jsonstring.tostring();                }else{         return "";     } } 

it giving me undefined : undefined... please me. stuck

try this:

function get_datatable() {     $.ajax({         url: "gridview_jqueryfunctionality.aspx/calldatatable_emptyrootname",         type: "post",         data: '{}',         contenttype: "application/json; charset=utf-8",         datatype: "json",         success: function (data) {             alert(data.d) // showing json fine             var mydata = $.parsejson(data.d)[""];              (i = 0; < mydata.length; i++) {                 alert(mydata[i].id + ' : ' + mydata[i].menuname);             }         }     }); } 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -