码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2016-05-05 09:47:14      阅读:265      评论:0      收藏:0      [点我收藏+]

标签:

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.

 

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

标签:

原文地址:http://www.cnblogs.com/c-x-a/p/5460563.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!