Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Json.php
Go to the documentation of this file.
1 <?php
7 
9 
16 class Json implements SerializerInterface
17 {
22  public function serialize($data)
23  {
24  $result = json_encode($data);
25  if (false === $result) {
26  throw new \InvalidArgumentException('Unable to serialize value.');
27  }
28  return $result;
29  }
30 
35  public function unserialize($string)
36  {
37  $result = json_decode($string, true);
38  if (json_last_error() !== JSON_ERROR_NONE) {
39  throw new \InvalidArgumentException('Unable to unserialize value.');
40  }
41  return $result;
42  }
43 }