gpt4 book ai didi

node.js - 在nodejs中解析jsonld

转载 作者:太空宇宙 更新时间:2023-11-03 23:23:57 25 4
gpt4 key购买 nike

我有一个 .jsonld 文件,我想读取并解析其中的数据。就像在 javascript 中一样,我们执行 JSON.parse。有没有类似或其他方式来解析nodejs中的jsonld数据。我的代码片段是:

{
"@context": "http://schema.org/",
"@type": "Person",
"name": "Peter Parker",
"jobTitle": "Spiderman",
"telephone": "(425) 123-4567",
"url": "http://www.spiderman.com"
}

最佳答案

fs.readFile('./.jsonid', 'utf8', (err, data) => {
if (err) throw err;
console.log(JSON.parse(data)); // do whatever you want here
});

使用fs从文件中读取内容,然后解析或对数据执行任何您想要的操作。

关于node.js - 在nodejs中解析jsonld,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46606058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com