-
Notifications
You must be signed in to change notification settings - Fork 1
PHP JsonHelper
Andrew Male edited this page Jul 27, 2015
·
2 revisions
The JsonHelper class provides several simple shortcut methods to perform simple actions related to JSON formatted data.
Automatically generated documentation for JsonHelper is available here:
http://n2framework.com/phpDoc/v2.0.1/classes/N2f.JsonHelper.html
The two methods available for decoding a JSON formatted string are little more than aliases for the appropriate calls to json_decode().
$json = "{ \"test\": \"value\" }";
$Jh = new \N2f\JsonHelper();
print_r($Jh->Decode($json));
// Outputs:
// stdClass Object
// (
// [test] => value
// )
print_r($Jh->DecodeAssoc($json));
// Outputs:
// Array
// (
// [test] => value
// )The two encoding methods are essentially calls to json_encode(), one directly and one with an attempt to make more human-readable output.
$data = array('test' => 'value');
echo($Jh->Encode($data));
// Outputs:
// {"test":"value"}
echo($Jh->EncodePretty($data));
// Outputs:
// {
// "test": "value"
// }