JSON 值轉換
阿新 • • 發佈:2017-07-04
key ole str code gif 正常 color stringify obj
1 var Txt = ‘{"a":"1","b":"5","c":"5","d":"6"}‘; 2 var arr1 = JSON.parse(Txt); 3 console.log(arr1) 4 // Object {a: "1", b: "5", c: "5", d: "6"} 5 // parse轉換的必須是正宗json值 如上 6 var txt = {"a":"1","b":"5","c":"5","d":"6"}; 7 var arr = JSON.stringify(txt); 8 console.log(arr)9 // {"a":"1","b":"5","c":"5","d":"6"} 10 // stringify可以正常轉對象 11 var ttt = {a:"1",b:"5",c:"5",d:"6"} 12 var arr2 = Object.keys(ttt) 13 console.log(arr2) 14 // ["a", "b", "c", "d"] 15 // Object.keys吧對象值都拿出來
JSON 值轉換