Skip to content

Instantly share code, notes, and snippets.

@mattn9x
Created July 2, 2017 06:46
Show Gist options
  • Save mattn9x/b8f644e6bb3b6d707bf3979bec89bccd to your computer and use it in GitHub Desktop.
Save mattn9x/b8f644e6bb3b6d707bf3979bec89bccd to your computer and use it in GitHub Desktop.
Deserialize và serialize object trong javascript
// 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