How to convert a request to a json object in jquery

This doesn't seem to be a problem, but of course there is either an internal js method or jquery to take a string, for example:

intTime=1324443870&fltOriginalAmount=0.00&strOriginalCurrency=GBP

... then much more vals and turn it into a JSON object?

I had to delve around this site and google and surprisingly painted spaces ... Has anyone got an easy way to do this?

+4
source share
2 answers

jQuery BBQ does just that. See $.deparam , "The opposite of jQuery.param, to a large extent."

 > var obj = $.deparam('intTime=1324443870&fltOriginalAmount=0.00&strOriginalCurrency=GBP') > JSON.stringify(obj) '{"intTime":"1324443870","fltOriginalAmount":"0.00","strOriginalCurrency":"GBP"}' 
+11
source

I used this hack ...

 $.parseJSON('{"' + qs.replace(/&/g, '","').replace(/=/g, '":"') + '"}'); 

demo here http://jsbin.com/niqaw/

+2
source

Source: https://habr.com/ru/post/1387316/


All Articles