This seems like a no brainer but surely there is either an internal js method or a jquery one to take a string like:
intTime=1324443870&fltOriginalAmount=0.00&strOriginalCurrency=GBP
...then a lot more vals and turn it into a JSON object?
I had a dig around this site and google and surprisingly drew blanks... Anyone got an easy way to do this?
This seems like a no brainer but surely there is either an internal js method or a jquery one to take a string like:
intTime=1324443870&fltOriginalAmount=0.00&strOriginalCurrency=GBP
...then a lot more vals and turn it into a JSON object?
I had a dig around this site and google and surprisingly drew blanks... Anyone got an easy way to do this?
Share Improve this question edited Dec 21, 2011 at 5:33 Timofey Stolbov 4,6313 gold badges41 silver badges46 bronze badges asked Dec 21, 2011 at 5:15 AlexAlex 3,7915 gold badges40 silver badges60 bronze badges 1- 2 There are no such thing as a "JSON object". Do you mean an object, or a JSON string? – Guffa Commented Dec 21, 2011 at 5:26
2 Answers
Reset to default 11jQuery BBQ does exactly this. See $.deparam
, "The opposite of jQuery.param, pretty much."
> var obj = $.deparam('intTime=1324443870&fltOriginalAmount=0.00&strOriginalCurrency=GBP')
> JSON.stringify(obj)
'{"intTime":"1324443870","fltOriginalAmount":"0.00","strOriginalCurrency":"GBP"}'
i used this hack...
$.parseJSON('{"' + qs.replace(/&/g, '","').replace(/=/g, '":"') + '"}');
demo here http://jsbin./niqaw/