Do you know a fast and simple way to encode a Javascript Object into a string
that I can pass via a GET
Request?
No jQuery
, no other frameworks - just plain Javascript :)
Do you know a fast and simple way to encode a Javascript Object into a string
that I can pass via a GET
Request?
No jQuery
, no other frameworks - just plain Javascript :)
like this?
Edit: this one also converts recursive objects (using php "array" notation for the query string)
The above answers fill not work if you have a lot of nested objects. Instead you can pick the function param from here - https://github.com/knowledgecode/jquery-param/blob/master/jquery-param.js It worked very well for me!
I made a comparison of JSON stringifiers and the results are as follows:
The shortest among them is URL Object Notation.
Rails / PHP Style Query Builder
This method converts a Javascript object into a
URI Query String
. Also handles nested arrays and objects (inRails
/PHP
syntax):Example Usage:
Addition for accepted solution, this works with objects & array of objects:
Also have added objName if you're using object parameters like in asp.net mvc action methods.