Utility/JsonParser.php
public function importString($content, $isMandatory = true)
    {
        if(empty($content) && $isMandatory)
        {
            throw new JsonException("Json content mandatory but none found.");
        }

        $this->params = array();
        if (!empty($content))
        {
            $this->params = @json_decode($content, true);

            if (json_last_error() !== JSON_ERROR_NONE) {
                throw new JsonException("Error parsing json content: '$content'. Error: " . json_last_error_msg());
            }

            if(null === $this->params)
            {
                // @codeCoverageIgnoreStart
                throw new JsonException("Error parsing json content: '$content'");
                // @codeCoverageIgnoreEnd
            }
        }
        return $this->params;
    }
public function importString($content, $isMandatory = true)
    {
        if(empty($content) && $isMandatory)
        {
            throw new JsonException("Json content mandatory but none found.");
        }

        $this->params = array();
        if (!empty($content))
        {
            $this->params = @json_decode($content, true);

            if (json_last_error() !== JSON_ERROR_NONE) {
                throw new JsonException("Error parsing json content: '$content'. Error: " . json_last_error_msg());
            }

            if(null === $this->params)
            {
                // @codeCoverageIgnoreStart
                throw new JsonException("Error parsing json content: '$content'");
                // @codeCoverageIgnoreEnd
            }
        }
        return $this->params;
    }
public function importString ( $ content , $ isMandatory = true ) { if ( empty ( $ content ) && $ isMandatory ) { throw new JsonException ( "Json content mandatory but none found." ) ; } $ this -> params = array ( ) ; if ( ! empty ( $ content ) ) { $ this -> params = @ json_decode ( $ content , true ) ; if ( json_last_error ( ) !== JSON_ERROR_NONE ) { throw new JsonException ( "Error parsing json content: '$content'. Error: " . json_last_error_msg ( ) ) ; } if ( null === $ this -> params ) { // @codeCoverageIgnoreStart throw new JsonException ( "Error parsing json content: '$content'" ) ; // @codeCoverageIgnoreEnd } } return $ this -> params ; }
Import string json and parse

@param  string  $content     string json
@param  boolean $isMandatory content is mandatory or can be empty - false
@return array                parsed json string
Import string json and parse