1. 程式人生 > >js json轉string string轉json

js json轉string string轉json

<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>

轉載於http://blog.csdn.net/huangcongjie/article/details/7591195