Created
November 22, 2012 20:24
-
-
Save soulcyon/4132805 to your computer and use it in GitHub Desktop.
Arbitrary JSON to PHP QueryString
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Sashank Tadepalli <[email protected]> | |
* @license Creative Commons Attribution 3.0 Unported License. | |
* @version 1.0 | |
* @link http://dijjit.com/js/arbitrary-json-to-php-querystring/ | |
*/ | |
function toQueryString(obj,inner){ | |
var build = ""; | |
for( t in obj ){ | |
if( !obj.hasOwnProperty(t) ) continue; | |
build += "&"; | |
var temp = (inner ? inner + "[" + (!(obj instanceof Array) ? t : "") + "]" : t); | |
build += typeof obj[t] == "object" ? toQueryString(obj[t], temp) : temp + "=" + obj[t]; | |
} | |
return build.substring(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment