Created
July 2, 2017 06:46
-
-
Save mattn9x/b8f644e6bb3b6d707bf3979bec89bccd to your computer and use it in GitHub Desktop.
Deserialize và serialize object trong javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// object person | |
var person = { | |
firstName: 'Nguyen', | |
lastName: 'Manh', | |
50: 'professional', | |
showName: function () { | |
console.log(this.firstName + ', ' + this.lastName); | |
} | |
}; | |
// Serialize | |
var strPerson = JSON.stringify(person); | |
console.log(strPerson); //{"50":"professional","firstName":"Nguyen","lastName":"Manh"} | |
// Note: serialize chi du lai cac thuoc tinh va lam mat di cac method | |
// Deserialize | |
var personDecode = JSON.parse(strPerson); | |
console.log(personDecode); // Object {50: "professional", firstName: "Nguyen", lastName: "Manh"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment