本文整理汇总了PHP中Helpers::jsonDecode方法的典型用法代码示例。如果您正苦于以下问题:PHP Helpers::jsonDecode方法的具体用法?PHP Helpers::jsonDecode怎么用?PHP Helpers::jsonDecode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Helpers
的用法示例。
在下文中一共展示了Helpers::jsonDecode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processRequestParams_json
protected function processRequestParams_json($_data)
{
return Helpers::jsonDecode($_data, 500);
}
示例2: decode
/**
* @param Http\Response
* @param array|NULL these codes are treated as success; code < 300 if NULL
* @return mixed
*
* @throws ApiException
*/
public function decode(Http\Response $response, array $okCodes = NULL)
{
$content = $response->getContent();
if (preg_match('~application/json~i', $response->getHeader('Content-Type', ''))) {
try {
$content = Helpers::jsonDecode($response->getContent());
} catch (JsonException $e) {
throw new InvalidResponseException('JSON decoding failed.', 0, $e, $response);
}
if (!is_array($content) && !is_object($content)) {
throw new InvalidResponseException('Decoded JSON is not an array or object.', 0, NULL, $response);
}
}
$code = $response->getCode();
if ($okCodes === NULL && $code >= 300 && $code != 304 || is_array($okCodes) && !in_array($code, $okCodes)) {
/** @var $content \stdClass */
switch ($code) {
case Http\Response::S400_BAD_REQUEST:
throw new BadRequestException($content->message, $code, NULL, $response);
case Http\Response::S401_UNAUTHORIZED:
throw new UnauthorizedException($content->message, $code, NULL, $response);
case Http\Response::S403_FORBIDDEN:
if ($response->getHeader('X-RateLimit-Remaining') === '0') {
throw new RateLimitExceedException($content->message, $code, NULL, $response);
}
throw new ForbiddenException($content->message, $code, NULL, $response);
case Http\Response::S404_NOT_FOUND:
throw new NotFoundException('Resource not found or not authorized to access.', $code, NULL, $response);
case Http\Response::S422_UNPROCESSABLE_ENTITY:
$message = $content->message . implode(', ', array_map(function ($error) {
return '[' . implode(':', (array) $error) . ']';
}, $content->errors));
throw new UnprocessableEntityException($message, $code, NULL, $response);
}
$message = $okCodes === NULL ? '< 300' : implode(' or ', $okCodes);
throw new UnexpectedResponseException("Expected response with code {$message}.", $code, NULL, $response);
}
return $content;
}
示例3: sendRequest_decodeData_json
public function sendRequest_decodeData_json($_data)
{
return Helpers::jsonDecode($_data);
}