Change language

PHP Json_decode () function

Syntax:
json_decode ($json, $assoc = FALSE, $depth = 512, $options = 0)
Options :This function takes four parameters as above and described below:
  • json:contains the JSON string to decode. Works only with UTF-8 encoded strings.
  • Assoc:is a boolean variable. If true, the returned objects will be converted to associative arrays.
  • depth:indicates the recursion depth specified by the user.
  • options: includes a bit mask JSON_OBJECT_AS_ARRAY, JSON_BIGINT_AS_STRING ,, JSON_THROW_ON_ERROR.
Return Values:This function returns an encoded JSON value in the appropriate PHP type. If json cannot be decoded, or if the encoded data is deeper than the recursion limit, it returns NULL.Below are examples to illustrate the use of the json_decode() function in PHP:
Example 1:  
// Declare the json string $json = ’{" g ": 7," e ": 5," e ": 5," k ": 11," s ": 19}’ ;  
// Use the json_decode() function for
// decode the string var_dump (json_decode ( $json )); var_dump (json_decode ( $json , true));  
?>
Exit:
object (stdClass ) # 1 (4) {["g"] = > int (7) ["e"] = > int (5) ["k"] = > int (11) ["s"] = > int (19)} array (4) {["g"] = > int (7) ["e"] = > int (5) ["k"] = > int (11) ["s"] = > int (19)}
Example 2:  
// Declare the json string $json = ’{" engineer ": 7551119}’ ;  
// Use the json_decode() function for
// decode the string $obj = json_decode ( $json );  
// Show json object value print $obj -> { ’engineer’ };  
?>
Exit:
7551119  Common mistakes when using the json_decode() function: 
  • The strings used are valid JavaScript, but not valid JSON.
  • Name and the value must be enclosed in double quotes, single quotes are not allowed.
  • Trailing commas are not allowed.
Link:http://php.net/manual/en/function.json-decode.php

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method