require_once 'Services/JSON.php'; $data = array( 'name' => 'John', 'age' => 30, 'email' => 'john@example.com' ); $json = new Services_JSON(); $output = $json->encode($data); echo $output; // {"name":"John","age":30,"email":"john@example.com"}
require_once 'Services/JSON.php'; $json_string = '{"name":"John","age":30,"email":"john@example.com"}'; $json = new Services_JSON(); $output = $json->decode($json_string); echo $output->name; // John echo $output->age; // 30 echo $output->email; // john@example.comIn this example, we have a JSON-encoded string that represents an object. We create a new instance of the Services_JSON class and use its decode method to convert the string into a PHP object. We can then access the data in the object using object notation. Overall, Services_JSON is a useful PHP package library for working with JSON data. It provides an easy-to-use interface for encoding and decoding JSON data, making it a popular choice for web developers who need to work with JSON data in their applications.