Hi I have the following JavaScript object, how could I serialize it to a string in the JSON data exchange format?
var result = { "id": "358464" ,"t" : "MSFT" ,"e" : "NASDAQ" ,"l" : "28.03" ,"l_cur" : "28.04" ,"s": "0" ,"ltt":"4:00PM EDT" ,"lt" : "Mar 15, 4:00PM EDT" ,"c" : "-0.10" ,"cp" : "-0.36" ,"ccol" : "chr" }
I tried JSON.stringify and JSON.parse and both did not work for me
The problem is that:
For example, result.l returns undefined.
What possible causes might this have? What could I be doing wrong?
Yes, it really works:
var str = '{ "id": "358464" ,"t" : "MSFT" ,"e" : "NASDAQ" ,"l" : "28.03" ,"l_cur" : "28.04" ,"s": "0" ,"ltt":"4:00PM EDT" ,"lt" : "Mar 15, 4:00PM EDT" ,"c" : "-0.10" ,"cp" : "-0.36" ,"ccol" : "chr" }';
var jsObj = JSON.parse(str);
console.dir(jsObj);
var jsonStrAgain = JSON.stringify(jsObj);
console.log(jsonStrAgain);
And this works as well (having nothing to do with JSON, just being an object literal):
var result = { "id": "358464" ,"t" : "MSFT" ,"e" : "NASDAQ" ,"l" : "28.03" ,"l_cur" : "28.04" ,"s": "0" ,"ltt":"4:00PM EDT" ,"lt" : "Mar 15, 4:00PM EDT" ,"c" : "-0.10" ,"cp" : "-0.36" ,"ccol" : "chr" };
console.log(result.l); // "28.03"