macrotux / jsonutils
JsonUtils, Utils for encode - decode JSON in PHP7, with control errors and Exception
Installs: 454
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/macrotux/jsonutils
Requires
- php: >=7.0
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());
}