Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to serialize an object in JavaScript?

For example I have class:

function Test() {
}

Test.prototype = {
    'setTest' : function(test) {
        this.test = test;
    }
}
var test = new Test();
Test.setTest('test');

I want to save object test in database. How to serialize object test to string? (methods, variables, etc)

like image 230
Bdfy Avatar asked Aug 01 '12 13:08

Bdfy


1 Answers

Simple with json

JSON.stringify( test );
like image 122
Roest Avatar answered Oct 13 '22 06:10

Roest