如何使用 Node.js 解析 JSON? [英] How to parse JSON using Node.js?
问题描述
我应该如何使用 Node.js 解析 JSON?是否有一些模块可以安全地验证和解析 JSON?
How should I parse JSON using Node.js? Is there some module which will validate and parse JSON securely?
推荐答案
您可以简单地使用 JSON.parse
.
You can simply use JSON.parse
.
JSON
对象的定义是 ECMAScript 5 规范的一部分.node.js 基于 Google Chrome 的 V8 引擎构建,该引擎符合 ECMA 标准.因此,node.js 也有一个全局对象 JSON
[文档].
The definition of the JSON
object is part of the ECMAScript 5 specification. node.js is built on Google Chrome's V8 engine, which adheres to ECMA standard. Therefore, node.js also has a global object JSON
[docs].
注意 - JSON.parse
可以占用当前线程,因为它是同步方法.因此,如果您打算解析大型 JSON 对象,请使用流式 json 解析器.
Note - JSON.parse
can tie up the current thread because it is a synchronous method. So if you are planning to parse big JSON objects use a streaming json parser.
这篇关于如何使用 Node.js 解析 JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!