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

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

时间:2014-12-07 00:02:03      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   io   ar   os   sp   java   strong   

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字符串之间的转换

标签:des   style   http   io   ar   os   sp   java   strong   

原文地址:http://www.cnblogs.com/wanghetao/p/4148989.html

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