最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - how do I convert a querystring into a json object in jquery - Stack Overflow

matteradmin3PV0评论

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
Add a ment  | 

2 Answers 2

Reset to default 11

jQuery 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/

Post a comment

comment list (0)

  1. No comments so far