json object and conversion

 

 

The key object 1 // double quotes can be added from time to increase, I felt no difference
@ var {obj = "name": "zhangsan", "Age": 18 is}
// var obj = {name: "zhangsan", Age: 18 is}

// the console.log (obj) {// name: "zhangsan", Age: 18 is}
// the console.log ( "name =" + obj.name) // name = zhangsan
// the console.log (typeof obj) // object

Objects turn json

console.log(JSON.stringify(obj))                     //{"name":"zhangsan","age":18}
console.log(typeof JSON.stringify(obj))          //string

 



2 // json must be enclosed in single quotes
// var STR = '{ "name": "Xiaojie"}'
// the console.log (STR) // { "name": "Xiaojie"}
// the console.log (typeof STR) // String

// turn JSON objects
// the JSON.parse (STR)
// the console.log (the JSON.parse (STR)) {// name: "Xiaojie"}
// the console.log (typeof the JSON .parse (STR)) // Object


. 3 // plurality of objects in the array, the data type is Object
var obj = [{ "name": "halun", "Age": 18 is}, { ". price": " 896 "," name ":" wangde "}, {" of He ":" ijie "," name ":" wangde "}]
Console.

console.log(obj[0])                                                                                                                                           //{name: "halun", age: "18"}

console.log(typeof obj)                                                                                                                                    //<object>

Objects turn json

console.log(JSON.stringify(obj))                                            //[{"name":"halun","age":18},{"price":"896","name":"wangde"},{"he":"ijie","name":"wangde"}]
console.log(typeof JSON.stringify(obj))                                   //string


// 利用循环拿到值
for(var i=0;i<obj.length;i++){
console.log(obj[i])                                        //{"name":"halun","age":18} {"price":"896","name":"wangde"} {"he":"ijie","name":"wangde"}
console.log(obj[i].name)                              // halun wangde
}

Guess you like

Origin www.cnblogs.com/shun1015/p/11568364.html