日期:2014-05-16  浏览次数:20325 次

js中的json对象和字符串之间的转化

1.首先要引入一个js文件,否则一些浏览器上用不了
json2.js
可以在https://github.com/douglascrockford/JSON-js 上下载

?

var a={"name":"heisetoufa","sex":"男","age":"29"};

  
var b='{"name":"zisetoufa","sex":"女","age":"24"}';

  
  
var aToStr=JSON.stringify(a);  

var bToObj=JSON.parse(b);  

alert(typeof(aToStr));//string  

alert(typeof(bToObj));//object  

?

?? 参考:http://www.oschina.net/code/snippet_175925_6288