2015-03-25 47 views
-1

我的数据存储是这样的:转换的JavaScript对象数组为字符串S3从蒙戈返回

[ { _id: 5510dcfb7ffb9ec87db017ca, 
deviceId: '150622', 
link: 'http://egauge15062.egaug.es/cgi-bin/egauge-show?S&s=0&n=6&C&Z=LST-8', 
timestamp: 1427168502, 
ct1: 3411, 
ct2: 532, 
ct3: 7, 
ct4: 43, 
ct5: 642 }, etc.........] 

我试图将数据存档到S3,我需要将其转换成字符串。我尝试在数组上使用.join和.tostring,当我将它推送到服务器时,它看起来像这样。

[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]] 

任何想法我可以解决这个问题。

回答

1
JSON.stringify(obj) 

其中,obj是要存储的JavaScript对象。

这将返回一个序列化的字符串,然后在您需要时可以轻松地在JavaScript中重新使用该字符串,这看起来与Mongo返回的内容完全相同。

+0

完美运作,谢谢! – 2015-03-25 04:56:41

+0

大副没问题,祝你好运。 – Burrito 2015-03-25 04:57:15