-9

您好我有以下 JavaScript 对象,如何将其序列化为 JSON 数据交换格式的字符串?

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" }

我试过了JSON.stringifyJSON.parse但都对我不起作用

问题是:

例如,result.l返回未定义。

这可能有哪些可能的原因?我可能做错了什么?

4

1 回答 1

2

是的,它确实有效:

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);

这也有效(与 JSON 无关,只是一个对象文字):

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"
于 2013-03-17T18:27:05.150 回答