NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - json_decode

Trieda

Koreň \ Bez triedy

Metóda - json_decode

(PHP 5 >= 5.2.0, PECL json >= 1.2.0, PHP 7)

Converts a JSON string into a PHP variable. On error, the json_last_error() function can be used to determine the exact error.

Procedurálne

  • function json_decode (string $json, bool $assoc = false, int $depth = 512, int $options = 0) : mixed

Parametre

NázovDátový typPredvolená hodnotaPopis
$jsonstring

The JSON to decode in the UTF-8 format.

$assocbool false

If this parameter is set to true, the returned PHP variable will be converted to an associative array.

$depthint 512

The depth limit of the recursion.

$optionsint 0

We can set 2 decoding options as a bitmask:

  • JSON_BIGINT_AS_STRING - Big integers are represented as strings instead of default floats.
  • JSON_OBJECT_AS_ARRAY - Has the same effect as setting the $assoc parameter to true.

Mávratovej hodnoty

Vracia: mixed

Returns the appropriate type of the JSON representation as a PHP variable. If JSON couldn't be decoded or the data are deeper than the recursion limit, returns null.

Príklady

<?php

$myJson = '{"name": "John", "age": "42", "male": true}';

var_dump(json_decode($myJson));

Súvisiace manuály

      • function json_encode (mixed $value, int $depth = 512) : string
      Aktivity