nodejs使用了google的v8 JavaScript引擎,内置的原生JSON对象支持序列化和反序列化操作,操作很方便,示例:
// demo-json.js var obj = { "name": "LiLi", "age": 22, "sex": "F" }; var str = JSON.stringify(obj); console.log(str); var obj2 = JSON.parse(str); console.log(obj2);执行:
#node demo-json.js
附参考链接:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/JSON
http://nodemanual.org/latest/js_doc/JSON.html