0

我有一本看起来像这样的字典:

[
  {
    link: '/listing/vasita-otomobil-audi-sahibinden-tertemiz-a3-sedan-849052103/detail',
    timestamp: 2020-09-02T16:26:41.007Z
  },
  {
    link: '/listing/vasita-otomobil-opel-mennan-autodan-opel-vectra-hatasiz-2008-lpgli-temiz-bakimli-856921177/detail',
    timestamp: 2020-09-02T16:26:41.007Z
  },
  {
    link: '/listing/vasita-otomobil-opel-2012-model-opel-corsa-1.3-cdti-essentia-75-ps-856923040/detail',
    timestamp: 2020-09-02T16:26:41.007Z
  },
  {
    link: '/listing/vasita-otomobil-fiat-kirca-otomotiv-2005-fiat-panda-cam-tavanli-otomatik-vites-856922600/detail',
    timestamp: 2020-09-02T16:26:41.007Z
  },..]

我希望能够将其保存为 json 文件。我这样做:

fs.writeFile('links.json', fs.write(JSON.stringify(pendingLinks)));  

它给出了这个错误:

TypeError [ERR_INVALID_ARG_TYPE]: The "fd" argument must be of type number. Received type string ('"[object Object],[object...)
4

1 回答 1

0

由于fs.write. 将内容写入文件所需要做的就是:

fs.writeFile('links.json', JSON.stringify(pendingLinks), (err) => console.log(err); 

您可能需要检查文档writeFilewriteFileSync在此处输入链接描述

于 2020-09-02T16:38:18.717 回答