Created
July 17, 2012 10:38
-
-
Save timblair/3128650 to your computer and use it in GitHub Desktop.
JSON encoding wrapper to handle CF 9.0.2's failure at serialising strings comprised of all zeroes.
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
component { | |
public string function encode(required any data) { | |
var json = serializeJSON(arguments.data); | |
if (!find("00", json)) { return json; } | |
if (left(json, 2) == "00") { json = '"#json#"'; } // just a simple value | |
// value in a structure | |
if (find('":00', json)) { json = rereplace(json, '[^\\]":([0]+)', '":"\1"', "ALL"); } | |
// value in an array (beginning, end, middle) | |
if (find('[00', json)) { json = rereplace(json, '[^\\]?\[([0]+)', '["\1"', "ALL"); } | |
if (find('00]', json)) { json = rereplace(json, ',([0]+)\]', ',"\1"]', "ALL"); } | |
if (find(',00', json) && find('00,', json)) { json = rereplace(json, ',([0]+),', ',"\1",', "ALL"); } | |
return json; | |
} | |
public string function decode(required string json) { | |
return deserializeJSON(arguments.json); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment