4

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?

1
  • 2
    There are no such thing as a "JSON object". Do you mean an object, or a JSON string? Commented Dec 21, 2011 at 5:26

2 Answers 2

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"}'
Sign up to request clarification or add additional context in comments.

2 Comments

so theres nothing internal to jquery or JS? Nice approach though, thank for this.
As far as I know, no, there is no "built-in" way.
1

i used this hack...

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.