Utility function used to create a new instance from a JSON string.

@param array $json a PHP array which contains the result of a 'json_decode' execution.

@return \Gomoob\Pushwoosh\Model\Response\CreateTargetedMessageResponse the resulting instance.
340597
public static function create(array $json)
    {
        $createTargetedMessageResponse = new CreateTargetedMessageResponse();
        $createTargetedMessageResponse->setStatusCode($json['status_code']);
        $createTargetedMessageResponse->setStatusMessage($json['status_message']);
    
        // If a 'response' is provided
        if (array_key_exists('response', $json) && isset($json['response'])) {
            $createTargetedMessageResponseResponse = new CreateTargetedMessageResponseResponse();
    
            // If 'messageCode' is provided
            if (array_key_exists('messageCode', $json['response'])) {
                $createTargetedMessageResponseResponse->setMessageCode($json['response']['messageCode']);
            }
    
            $createTargetedMessageResponse->setResponse($createTargetedMessageResponseResponse);
        }
    
        return $createTargetedMessageResponse;
    }
236908
public static function convert(array $json)
    {
        $loader  = new ArrayLoader;
        $package = $loader->load($json);


        if ($package instanceof CompletePackage) {
            return $package;
        }

        // @codeCoverageIgnoreStart
        throw new InvalidPackageException(
            'Expected instance of CompletePackage, got '.get_class($package)
        );
        // @codeCoverageIgnoreEnd
    }
186328
public static function fromJson($json)
    {
        $responseData = json_decode($json, true);

        if (! $responseData) {
            return new Response(false, ['invalid-json']);
        }

        if (isset($responseData['success']) && $responseData['success'] == true) {
            return new Response(true);
        }

        if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) {
            return new Response(false, $responseData['error-codes']);
        }

        return new Response(false);
    }
125671
public static function makeFromJson(JsonResponse $json)
    {
        $content = $json->getContent();

        // If the contents of the JsonResponse does not starts with /**/ (typical laravel jsonp response)
        // we assume that it is a valid json response that can be decoded, or we just use the raw jsonp
        // contents for building the response
        if (! starts_with($json->getContent(), '/**/')) {
            $content = json_decode($json->getContent(), true);
        }

        $new = static::create($content, $json->getStatusCode());

        $new->headers = $json->headers;

        return $new;
    }
337558
public function searchFromJson($json)
    {
        if (is_string($json)) {
            $json = yii\helpers\Json::decode($json);
        }
        if (isset($json['mainEntityClassName'], $json['searchQuery']) === false) {
            throw new \RuntimeException("mainEntityClassName and searchQuery needed to be in json for search");
        }
        $mainEntityClassName = $json['mainEntityClassName'];
        $q = new SearchQuery($mainEntityClassName, $this, $json['searchQuery']);
        $q->pagination($q->pagination);
        return $q;
    }
146423
public static function jsonToArray($json = false) {

        if ($json && Validate::isJson($json)) {

            $object = json_decode($json);
            return self::objectToArray($object);
        }

        return false;
    }
1107223
public static function createGrammar($json): Grammar
    {
        $array = json_decode($json, true);
        if (null === $array && 'null' !== $json) {
            throw new \InvalidArgumentException('JSON error: ' . json_last_error_msg());
        }
        if (!is_array($array)) {
            throw new \InvalidArgumentException('Incorrect JSON data');
        }

        return parent::createGrammar($array);
    }
368545
public static function fromJson($json)
    {
        $object = json_decode($json);

        $recurrentPayment = new RecurrentPayment();

        if (isset($object->RecurrentPayment)) {
            $recurrentPayment->populate($object->RecurrentPayment);
        }

        return $recurrentPayment;
    }
117944
public function decode($json)
    {
        $data = json_decode($json, true);
        if ($data === null && json_last_error() != JSON_ERROR_NONE) {
            throw new JsonSerializerException('Invalid JSON to unserialize.');
        }

        if (!is_array($data)) {
            throw new JsonSerializerException('Given JSON cannot represent an object.');
        }

        if (mb_strpos($json, $this->encodingAnnotation) !== false) {
            $data = $this->decodeNonUtf8FromUtf8($data);
        }

        return $data;
    }
1285897
public static function createFromJsonResponse($data)
    {
        $data = json_decode($data, true);

        $stacks = array_map(function ($stack) {
            return Stack::createFromDecodedJsonResponse($stack);
        }, $data['items']);

        return new self($stacks);
    }
966954
public static function fromJson($json)
    {
        $data = json_decode((string)$json, true);

        if (json_last_error() !== JSON_ERROR_NONE || !is_array($data)) {
            throw new \UnexpectedValueException('Invalid JSON message.');
        }

        return new static($data);
    }
913626
public static function unwrapJSON($json): self {
        if (is_string($json)) {
            $json = json_decode($json, true);
        }
        $recipient = new static;
        $recipient->setEndpoint($json['endpoint']);
        $recipient->setIdentifier(array_reverse(explode('/', $json['endpoint']))[0]);
        $recipient->setAuthKey($json['keys'][static::AUTH_KEY]);
        $recipient->setAuthSecret($json['keys'][static::AUTH_SECRET]);
        return $recipient;
    }
863330
public static function fromJson($json)
    {
        $responseData = json_decode($json, true);

        if ( ! $responseData)
            return new static(false, [ResponseV3::E_INVALID_JSON]);

        return static::fromArray($responseData);
    }
609054
public static function decode($json)
    {
        $flags = 0;
        if (PHP_INT_SIZE === 4) {
            $flags |= JSON_BIGINT_AS_STRING;
        }
        $data = json_decode($json, false, 512, $flags);
        $error = json_last_error();
        if ($error !== JSON_ERROR_NONE) {
            throw new \InvalidArgumentException(sprintf('Failed to decode JSON (%d): %s.', $error, json_last_error_msg()));
        }

        return $data;
    }
518363
protected function resourcePostErrorResponse($json)
    {
        $error = new Error('Unprocessable Entity', json_decode($json));

        return $this->createResponse(new UnprocessableEntity([$error]));
    }
1261847
public static function jsonToArray($json)
    {
        if (empty($json)) {
            return null;
        }

        $array = json_decode($json, true);

        switch (json_last_error()) {
            case JSON_ERROR_NONE:
                $message = null;
                break;

            case JSON_ERROR_STATE_MISMATCH:
                $message = 'Invalid or malformed JSON';
                break;

            case JSON_ERROR_UTF8:
                $message = 'Malformed UTF-8 characters, possibly incorrectly encoded';
                break;

            case JSON_ERROR_DEPTH:
                $message = 'The maximum stack depth has been exceeded';
                break;

            case JSON_ERROR_CTRL_CHAR:
                $message = 'Control character error, possibly incorrectly encoded';
                break;

            case JSON_ERROR_SYNTAX:
                $message = 'Syntax error, malformed JSON';
                break;

            default:
                $message = 'Unknown error';
                break;
        }

        if (!empty($message)) {
            throw new \InvalidArgumentException('JSON Error: ' . $message);
        }

        return $array;
    }
892503
protected function resourcePatchErrorResponse($json)
    {
        $error = new Error('Unprocessable Entity', json_decode($json));

        return $this->createResponse(new UnprocessableEntity([$error]));
    }