Skip to content Skip to sidebar Skip to footer

Good Way To Serialize A List? - Javascript/ajax

just felt like asking this as there are always jewels popping up on stackoverflow :) What I have is the following list: list1 = [['command','arg1','arg2'], ['command2','arg1'], ...

Solution 1:

Convert it to json then encode the characters using encodeURI.

var list1 = [['command','arg1','arg2'], ['command2','arg1']];
var encoded = encodeURI(JSON.stringify(list1));

alert(encoded);

Edit for base64:

var list1 = [['command','arg1','arg2'], ['command2','arg1']];
var encoded = btoa(JSON.stringify(list1));

alert(encoded);
alert(atob(encoded));

Solution 2:

Post a Comment for "Good Way To Serialize A List? - Javascript/ajax"