Javascript 在 Node.js 中,如何将字符串转换为 json?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5801699/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 18:56:12 来源:igfitidea点击:
In Node.js, how do I turn a string to a json?
提问by TIMEX
For example, a HTTP REST API just returned me a JSON, but of course it's a string right now. How can I turn it into a JSON?
例如,一个 HTTP REST API 刚刚返回给我一个 JSON,但当然它现在是一个字符串。我怎样才能把它变成一个 JSON?
回答by Olical
You need to use this function.
您需要使用此功能。
JSON.parse(yourJsonString);
And it will return the object / array that was contained within the string.
它将返回包含在字符串中的对象/数组。
回答by neebz
use the JSON function >
使用 JSON 函数 >
JSON.parse(theString)