【发布时间】:2019-12-22 05:16:51
【问题描述】:
当我打印一个变量时,节点 Js 会得到这样的值
Supercluster {
options: { log: true, radius: 60, extent: 512, maxZoom: 16 },
trees:
[ KDBush {
nodeSize: 64,
points: [Array],
ids: [Uint16Array],
coords: [Float32Array] },
KDBush {
nodeSize: 64,
points: [Array],
ids: [Uint16Array],
coords: [Float32Array] },
KDBush {
nodeSize: 64,
points: [Array],
ids: [Uint16Array],
coords: [Float32Array] }
]};
我想将其写入一个文件。我正在使用以下代码
fs.writeFile('./filename.json', json, err => {
if (err) {
console.log('Error writing file', err)
} else {
console.log('Successfully wrote file')
}
});
创建执行文件后但仅在文件内部[object Object]
然后我使用了JSON.stringify(clusterPacked),但我的值格式发生了变化
Supercluster 和 KDBush 都被删除了,我的输出就像
{ options: { log: true, radius: 60, extent: 512, maxZoom: 16 },
trees:
[ { nodeSize: 64, points: [Array], ids: [Object], coords: [Object] },
{ nodeSize: 64, points: [Array], ids: [Object], coords: [Object] }
]
};
我只想按原样保存格式。
【问题讨论】:
标签: javascript node.js file express fs