wcf - extract data from json -


i have json data coming wcf servicein jquery

getbedtypelist1result1 function in wcf

{     "getbedtypelist1result":[         {"code":23,"companycode":null,"decode":"1 class new born bed","divisioncode":0,"locationcode":0,"admduedepamt":0,"bedtypecode":0,"casetypecode":0,"casetypedecode":null,"ptnclasscode":0,"ptnclassdecode":null,"rsvduedepamt":0},         {"code":22,"companycode":null,"decode":"1st class bed","divisioncode":0,"locationcode":0,"admduedepamt":0,"bedtypecode":0,"casetypecode":0,"casetypedecode":null,"ptnclasscode":0,"ptnclassdecode":null,"rsvduedepamt":0},         {"code":5,"companycode":null,"decode":"classique bed","divisioncode":0,"locationcode":0,"admduedepamt":0,"bedtypecode":0,"casetypecode":0,"casetypedecode":null,"ptnclasscode":0,"ptnclassdecode":null,"rsvduedepamt":0}     ],     "strerrmsg":"y",     "chrerrflg":"c" } 

i calling service below

         function callwcfservice() {          //alert("callwcfservicexxxx");          jquery.ajax         (          {               type: type,              url: url,              data: parameters,              contenttype: contenttype, // content type sent server              datatype: datatype, //expected data format server              cache: "false",              crossdomain: true,   //same result if remove line              processdata: processdata, //true or false              success: function (msg)               {                  servicesucceeded(msg);              },              error: servicefailed// when service call fails          }        );      }         function callservice()       {          datatype = "json";          type = "get";          var par = 4;          parameters = null;          url = "http://192.168.2.42/cwserverwcf/bedtypemasterservice.svc/getbedtypelist?callback=?";          parameters = "{'strerrmsg':'1'},{'chrerrflg':'a'},{'pcompanycode':'0'},{'pdiv':'1'},{'ploc':'1'}";         // alert(parameters);          contenttype = "application/json; charset=utf-8";          processdata = true;          //alert("sssssasasadsds");          callwcfservice();      } 

i trying fetch data not getting lke below

   function servicesucceeded(result)       {          if (datatype == "json")         {            var obj =  jquery.parsejson(json.stringify(json.stringify(result)));            (var x = 0; x < obj.length; x++)              {              }          }      } 

in obj.length count of characters coming , jquery.parsejson(result) not working

please help

if result json there no need parse in way. jquery.ajax return javascript object if datatype set json.

so in servicesucceeded function may operate on result variable directly. if trying iterate on bed types change loop this:

for (var = 0; < result.getbedtypelist1result.length; i++) {   // ...do stuff   // var bed = result.getbedtypelist1result[i]] } 

Comments