Art4\JsonApiClient\Utils\Manager::parse PHP Method

parse() public method

Parse a JSON API string into an object
public parse ( string $string ) : Art4\JsonApiClient\AccessInterface
$string string The JSON API string
return Art4\JsonApiClient\AccessInterface
    public function parse($string)
    {
        $object = Helper::decodeJson($string);
        $document = $this->getFactory()->make('Document', [$this]);
        $document->parse($object);
        return $document;
    }

Usage Example

Beispiel #1
0
 public function parse(Response $response)
 {
     if ($response->getStatusCode() !== 200) {
         return false;
     }
     $jsonResponse = $response->getBody()->getContents();
     $jsonapi = new JsonManager();
     try {
         $parsed = $jsonapi->parse($jsonResponse);
     } catch (ValidationException $e) {
         return false;
     }
     return $parsed;
 }