just felt like asking this as there are always jewels popping up on stackoverflow :)
What I have is the following list:
list1 = [['mand','arg1','arg2'], ['mand2','arg1'], ... ]
How would you remend to transform it into a string in order to be passed as ONE GET argument?
e.g.
/?data=...
What I am currently doing is separating lists using mas ,
;
, but I don't like this idea as the method would break if I decide to introduce these within strings.
I'm trying to be as pact as possible.
One idea I've had is to encode the list into base64:
[['mand','arg1','arg2'], ['mand2','arg1']]
=> "W1snY29tbWFuZCcsJ2FyZzEnLCdhcmcyJ10sWydjb21tYW5kMicsJ2FyZzEnXV0="
which is shorter than URIencode
Any ideas? :)
just felt like asking this as there are always jewels popping up on stackoverflow :)
What I have is the following list:
list1 = [['mand','arg1','arg2'], ['mand2','arg1'], ... ]
How would you remend to transform it into a string in order to be passed as ONE GET argument?
e.g.
http://webgame_site./mand_list/?data=...
What I am currently doing is separating lists using mas ,
;
, but I don't like this idea as the method would break if I decide to introduce these within strings.
I'm trying to be as pact as possible.
One idea I've had is to encode the list into base64:
[['mand','arg1','arg2'], ['mand2','arg1']]
=> "W1snY29tbWFuZCcsJ2FyZzEnLCdhcmcyJ10sWydjb21tYW5kMicsJ2FyZzEnXV0="
which is shorter than URIencode
Any ideas? :)
Share Improve this question edited Dec 22, 2010 at 3:32 RadiantHex asked Dec 22, 2010 at 3:15 RadiantHexRadiantHex 25.6k47 gold badges155 silver badges251 bronze badges2 Answers
Reset to default 4Convert it to json then encode the characters using encodeURI.
var list1 = [['mand','arg1','arg2'], ['mand2','arg1']];
var encoded = encodeURI(JSON.stringify(list1));
alert(encoded);
Edit for base64:
var list1 = [['mand','arg1','arg2'], ['mand2','arg1']];
var encoded = btoa(JSON.stringify(list1));
alert(encoded);
alert(atob(encoded));
jQuery.param() sounds good.