JSON Object
JSON Objects
{ "name":"junlan", "age":30, "car":"vw" }
Accessing Object Values
myObj = { "name":"junlan", "age":30, "car":"vw" };
- x = myObj.name;
- x = myObj["name"];
Looping an Object
You can loop through object properties by using the for-in loop:
Example
myObj = { "name":"junlan", "age":30, "car":"vw" };
for (x in myObj) {
var obj=myObj[x];
}
Nested JSON Objects
myObj = {
"name":"junlan",
"age":30,
"cars": {
"car1":"Ford",
"car2":"BMW",
"car3":"Fiat"
}
}
x = myObj.cars.car2;
// or:
x = myObj.cars["car2"];
Modify Values
myObj.cars.car2 = "Mercedes";
myObj.cars["car2"] = "Mercedes";
Delete Object Properties
delete myObj.cars.car2;
Comments
Post a Comment