node.js JS对象和JSON字符串之间的转换

JSON.stringify(obj)将JS对象转为字符串

var json = { aa: ['sdddssd'],
  bb: [ '892394829342394792399', '23894723984729374932874' ],
  cc: ['11111111111111'] }

=> var string = JSON.stringify(json)

string:

{"aa":["sdddssd"],"bb":["892394829342394792399","23894723984729374932874"],"cc":["11111111111111"]}


JSON.parse(string)将字符串转为JS对象

JSON.parse(string):

=>

{ aa: ['sdddssd'],
  bb: [ '892394829342394792399', '23894723984729374932874' ],
  cc: ['11111111111111'] }

 

 

You can simply use JSON.parse.

node.js is built on V8, which provides the global object JSON[docs]. The definition of the JSON object is part of the ECMAScript 5 specification.

 

posted on 2016-09-06 18:09  youfeng  阅读(11578)  评论(0编辑  收藏  举报

导航