首頁 >web前端 >js教程 >JSON字串和js物件轉換

JSON字串和js物件轉換

高洛峰
高洛峰原創
2016-11-18 11:40:261363瀏覽

js資料型態:

字串、數字、布林、陣列、物件、Null、Undefined

js Object

var data = {
    "name":"yfs",
    "age":28,
    "boy":true,
    "language":["chinese", "english"],
    "address":{
        "provice":"shanxi",
        "city":"xian"
    }
};

JSON.stringify();

var jsonString = JSON.stringify(data);
console.log(jsonString);
console.log(typeof(jsonString));//结果:
 {"name":"yfs","age":28,"boy":true,"language":["chinese","english"],"address":{"p
rovice":"shanxi","city":"xian"}}//类型:stringvar a = '{"name":"yfs","age":28,"boy":true,"language":["chinese","english"],"address":{"p
rovice":"shanxi","city":"xian"}}';

JJ.

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn