Creates a response object from a JSON message.

@param string $json A JSON string.

@return Response The parsed response.
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);
    }
3673
public static function parse($json)
	{
		// 验证json格式

		$params = json_decode($json, true);

		$obj = new Task();
		$obj->id = $params['id'];
		$obj->name = $params['name'];
		$obj->type = (int) $params['type'];
		$obj->body = TaskBody::parse($params['body']);

		return $obj;
	}
639515
public static function create(array $json)
    {
        $registerDeviceResponse = new RegisterDeviceResponse();
        $registerDeviceResponse->setStatusCode($json['status_code']);
        $registerDeviceResponse->setStatusMessage($json['status_message']);

        return $registerDeviceResponse;
    }
1177950
public static function create(array $json)
    {
        $getTagsResponse = new GetTagsResponse();
        $getTagsResponse->setStatusCode($json['status_code']);
        $getTagsResponse->setStatusMessage($json['status_message']);

        // If a 'response' is provided
        if (array_key_exists('response', $json) && isset($json['response'])) {
            $getTagsResponseResponse = new GetTagsResponseResponse();

            // If a 'result' is provided
            if (array_key_exists('result', $json['response'])) {
                $getTagsResponseResponse->setResult($json['response']['result']);
            }

            $getTagsResponse->setResponse($getTagsResponseResponse);
        }

        return $getTagsResponse;
    }
782629
public function answer($json = null, $corsPreflight = false)
    {
        $answer = new HTTPResponse();

        //set response body
        if (!$corsPreflight) {
            $answer->setBody($json);
        }

        //set CORS if needed
        $answer = $this->setAnswerCORS($answer);

        $answer->addHeader('Content-Type', $this->serializer->getcontentType());

        // save controller's response then return/output
        $this->response = $answer;

        return $answer;
    }
1036006
public function decode($json)
    {
        if (empty($json)) {
            return '';
        }
        $decoded = json_decode($json, true);
        if (null !== $decoded) {
            return $decoded;
        }
        if (JSON_ERROR_NONE === json_last_error()) {
            return $json;
        }

        return self::$jsonErrors[json_last_error()];
    }
278196
private function jsonToArray($json)
	{
		try {
			$data = json_decode($json, true);
			if(is_array($data)) {
				return $data;
			}
			else {
				$this->error = 'The given data string was not json';
				return [];
			}
		}
		catch(Exception $e) {
			$this->error = $e;
		}
	}
462468
private function jsonResponse($data)
    {
        $response = new Response(json_encode($data));
        $response->headers->set('Content-Type', 'application/json');
        return $response;
    }
962800
public static function fromJson($json){
    if(is_string($json)){
      $json = json_decode($json);
    }

    if (!isset($json->error) || is_null($json->error) ) {
      return new self($json->uuid, new DateTime($json->timestamp), $json->status);
    } else {
      if(!property_exists($json->error, 'code')){
        throw new BadResponseException('Required parameter "error.code" not found');
    }
      throw AbstractReport::errorToException($json->error->code);
    }
  }
729920
public function getResponseObject(string $class, string $json)
    {
        $object = $this->deserialize($class, $json);
        $this->assertValid($object, ValidationException::RESPONSE);

        return $object;
    }
1249048
public static function fromJson($json){
    if(is_string($json)){
      $json = json_decode($json);
    }
    
    if(!property_exists($json, 'total')){
      throw new BadResponseException('Required parameter "total" not found');
    }
    if(!property_exists($json, 'fns_site')){
      throw new BadResponseException('Required parameter "fns_site" not found');
    }
    if(!property_exists($json, 'fn_number')){
      throw new BadResponseException('Required parameter "fn_number" not found');
    }
    if(!property_exists($json, 'shift_number')){
      throw new BadResponseException('Required parameter "shift_number" not found');
    }
    if(!property_exists($json, 'receipt_datetime')){
      throw new BadResponseException('Required parameter "receipt_datetime" not found');
    }
    if(!property_exists($json, 'fiscal_receipt_number')){
      throw new BadResponseException('Required parameter "fiscal_receipt_number" not found');
    }
    if(!property_exists($json, 'fiscal_document_number')){
      throw new BadResponseException('Required parameter "fiscal_document_number" not found');
    }
    if(!property_exists($json, 'fiscal_document_attribute')){
      throw new BadResponseException('Required parameter "fiscal_document_attribute" not found');
    }
    if(!property_exists($json, 'ecr_registration_number')){
      throw new BadResponseException('Required parameter "ecr_registration_number" not found');
    }

    return new self(
      $json->total,
      $json->fns_site,
      $json->fn_number,
      $json->shift_number,
      new DateTime($json->receipt_datetime),
      $json->fiscal_receipt_number,
      $json->fiscal_document_number,
      $json->fiscal_document_attribute,
      $json->ecr_registration_number
    );
  }
411355
public static function parse($json)
    {
        $json = json_decode($json);

        if (!isset($json->status)) {
            throw new JSendParseException('Could not parse data; required element \'status\' missing.');
        }

        $instance = new static($json->status);

        if (!isset($json->code)) {
            $json->code = 200;
        }
        $instance->setCode($json->code);

        if ($instance->isError()) {
            if (!isset($json->message)) {
                throw new JSendParseException('Could not parse data; required element \'message\' missing.');
            }
            $instance->setMessage($json->message);
        }

        if ($instance->isSuccess() || $instance->isFail()) {
            if (!isset($json->data)) {
                throw new JSendParseException('Could not parse data; required element \'data\' missing.');
            }
            $instance->setData($json->data);
        } else {
            if ($instance->isError()) {
                if (isset($json->data)) {
                    $instance->setData($json->data);
                }
            }
        }

        return $instance;
    }
1159823
private function decodeJson( $json ) {
		$error = $errorMsg = null;
		$return = json_decode( $json );
		if ( $return === null && trim( $json ) !== 'null' ) {
			$error = json_last_error();
			$errorMsg = json_last_error_msg();
		} elseif ( !$return || !is_object( $return ) ) {
			$error = 128;
			$errorMsg = 'Response must be an object';
		}

		if ( $error ) {
			$this->logger->error(
				'Failed to decode server response as JSON: {message}',
				[
					'response' => $json,
					'code' => json_last_error(),
					'message' => json_last_error_msg(),
				]
			);
			throw new Exception( 'Decoding server response failed: ' . json_last_error_msg()
				. " (Raw response: $json)" );
		}
		return $return;
	}
12021
public static function json2arr($json)
    {
        $result = json_decode($json, true);
        if (empty($result)) {
            throw new InvalidResponseException('invalid response.', '0');
        }
        if (!empty($result['errcode'])) {
            throw new InvalidResponseException($result['errmsg'], $result['errcode'], $result);
        }
        return $result;
    }
743438
public function dontSeeResponseContainsJson($json = [])
    {
        $jsonResponseArray = new JsonArray($this->connectionModule->_getResponseContent());
        $this->assertFalse(
            $jsonResponseArray->containsArray($json),
            "Response JSON contains provided JSON\n"
            . "- <info>" . var_export($json, true) . "</info>\n"
            . "+ " . var_export($jsonResponseArray->toArray(), true)
        );
    }
518363
protected function resourcePostErrorResponse($json)
    {
        $error = new Error('Unprocessable Entity', json_decode($json));

        return $this->createResponse(new UnprocessableEntity([$error]));
    }
1364809
public static function fromJson($json)
    {
        if (!is_object($json)) {
            $json = json_decode($json);
        }
        $properties = ['package', 'description', 'url', 'sha1', 'depth'];
        $patch = new static();

        foreach ($properties as $property) {
            if (isset($json->{$property})) {
                $patch->{$property} = $json->{$property};
            }
        }

        return $patch;
    }