macrotux/jsonutils

This package is abandoned and no longer maintained. No replacement package was suggested.

JsonUtils, Utils for encode - decode JSON in PHP7, with control errors and Exception

1.0 2016-05-09 15:10 UTC

This package is not auto-updated.

Last update: 2018-09-29 20:45:53 UTC


README

Utils for encode - decode JSON in PHP7, with control errors and Exception

Composer

"require": {
 "php": ">=7.0",
  "macrotux/jsonutils": "dev-master"
},

Examples

Encode Array

try {
  $strJson = \JsonUtils\JsonUtils::encodeArray(["foo"=>"bar"]);
}  catch (\JsonUtils\ExceptionJsonError $e) {
  error_log($e->getMessage());
}

Encode Obj

try {
  $strJson = \JsonUtils\JsonUtils::encodeObj( new \stdClass() );
}  catch (\JsonUtils\ExceptionJsonError $e) {
  error_log($e->getMessage());
}

Decode Json string Object

try {
  $strJson = \JsonUtils\JsonUtils::decodeToObject('{"foo":"bar"}'); // return \stdClass
}  catch (\JsonUtils\ExceptionJsonError $e) {
  error_log($e->getMessage());
}

Decode Json string array

try {
  $strJson = \JsonUtils\JsonUtils::decodeToArray('{"foo":"bar"}'); // return Array
}  catch (\JsonUtils\ExceptionJsonError $e) {
  error_log($e->getMessage());
}