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 @ 2016-05-05 09:18  公众号python学习开发  阅读(749)  评论(0编辑  收藏  举报