String to object in Javascript -
i have function working fine:
function sendleaddata(form) { return trk(form, { firstname: "pan", }); }
{firstname : "pan"}
= object. if set var , pass var in function works fine. need use string building map , pass that. getting string perfect .code below not working:
function sendleaddata(form) { //code str alert("str "+str);------->prints str perfect,also giving result below var obj = json.parse(str);//if except str put json.parse(json.stringify({firstname:"pan"})) work fine alert("obj "+obj); return trk(form, obj ); }
str prints "{firstname:"pan"}". error syntax error thrown.
please help.
json has more strict object representation. keys need quoted:
'{"firstname": "pan"}'
Comments
Post a Comment