如何使用Node.js解析JSON? [英] How to parse JSON using Node.js?

查看:131
本文介绍了如何使用Node.js解析JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该如何使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆