Created
November 16, 2011 13:30
-
-
Save biomood/1370076 to your computer and use it in GitHub Desktop.
Postify method, send complex JSON to MVC
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
$.postify = function(value) { | |
var result = {}; | |
var buildResult = function(object, prefix) { | |
for (var key in object) { | |
var postKey = isFinite(key) | |
? (prefix != "" ? prefix : "") + "[" + key + "]" | |
: (prefix != "" ? prefix + "." : "") + key; | |
switch (typeof (object[key])) { | |
case "number": case "string": case "boolean": | |
result[postKey] = object[key]; | |
break; | |
case "object": | |
if (object[key].toUTCString) | |
result[postKey] = object[key].toUTCString().replace("UTC", "GMT"); | |
else { | |
buildResult(object[key], postKey != "" ? postKey : key); | |
} | |
} | |
} | |
}; | |
buildResult(value, ""); | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment