Skip to content

Instantly share code, notes, and snippets.

@akinazuki
Created December 15, 2018 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akinazuki/6c3f92feb2cf147aee15a5977aa3c0b6 to your computer and use it in GitHub Desktop.
Save akinazuki/6c3f92feb2cf147aee15a5977aa3c0b6 to your computer and use it in GitHub Desktop.
<?php
class JSON {
public static function Decode($string, $return_array = false, $depth = 512, $options = 0) {
$res = json_decode($string, $return_array, $depth, $options);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new Exception(json_last_error(), json_last_error_msg());
}
return $res;
}
public static function Encode($array, $options = 0, $depth = 512) {
$res = json_encode($array);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new Exception(json_last_error(), json_last_error_msg());
}
return $res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment