Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am converting datatable to json string and getting output as
JavaScript
"[{"CompanyName":"Crisil","POM_Name":"No Interview scheduled","RoundTime":"","Contactnumber":"","Contactperson":"","Address":""}]"


when i'm parsing this string i'm getting object 'undefined'

My Code
JavaScript
var objdata = $.parseJSON(data.d);
//alert(objdata);
//var objdata = JSON.parse(data.d);
alert(obj['CompanyName']); // this object shows "undefined"


How to parse this?

Thanks in Advance.
Posted
Comments
Andy Lanng 11-Aug-15 5:43am    
I see that you have been toying with this to get it to work, but...
... In this version you are looking at obj which I do not see being defined.
If this is just a typo then please use the Improve Question button to update the code.

Thanks ^_^

1 solution

You have two problems...
1. A mixture of variable names between obj and objdata...You parse the JSON into objdata but try to display data from obj...
2. You JSON is an array(!) of objects, but you try to access it as a single object...
JavaScript
var data = '[{"CompanyName":"Crisil","POM_Name":"No Interview scheduled","RoundTime":"","Contactnumber":"","Contactperson":"","Address":""}]';
var obj = $.parseJSON(data); 
alert(obj[0]['CompanyName']);
 
Share this answer
 
Comments
Herman<T>.Instance 11-Aug-15 6:52am    
Good explanation +5
Kornfeld Eliyahu Peter 11-Aug-15 6:53am    
Thank you...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900