/** * 本静态方法在64位时,将和原生调用json_decode一致; * 在32位操作系统时,将强制使用或者模拟php 5.4的JSON_BIGINT_AS_STRING, * 以解决在32位操作系统时的bigint转换错误导致精度丢失问题。 * 本静态方法仅采用前两位参数。 * @static * @see http://www.php.net/manual/en/function.json-decode.php * @param string $json * @param bool[optional] $assoc */ function decode($json, $assoc = false) { switch (xwb_util_json::get_decode_type()) { case 0: return json_decode($json, $assoc); break; case 1: return json_decode($json, $assoc, 512, JSON_BIGINT_AS_STRING); break; default: $json = preg_replace('#(?<=[,\\{\\[])\\s*("\\w+"):(\\d{6,})(?=\\s*[,\\]\\}])#si', '${1}:"${2}"', $json); return json_decode($json, $assoc); break; } }