js json 把json对象转成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://heisetoufa.iteye.com/

你可能感兴趣的:(JavaScript,js,json,json2.js,json对象转成字符串)