Serialize name/value pairs
Why do you want it serialized specifically in that form? Just use the universal, built-in JSON serialization:

var serialized = JSON.stringify(myvar);
var reconstituted = JSON.parse(serialized);


Done, reconstituted is a normal object again.