Js Json对象与String互转

ghjcduhvfyjhbf 2015-10-13

<script type="text/javascript" src="./json2.js"></script>

<script type="text/javascript"n>
//把json 字符串转换成对象
var string = '{"name":"frank", "age":29, "birthday":"1978-1-1"}';
var user = JSON.parse(string);
alert(user.name);
alert(user.age);
alert(user.birthday);
//把对象转换成json字符串
alert (JSON.stringify(user))

</script>

相关推荐