How to decode an array of json objects

I have an array of json objects like:

[{"a":"b"},{"c":"d"},{"e":"f"}]

What is the best way to turn this into a php array?

json_decode will not process part of the array and returns NULL for this string.

+4
source share
2 answers

json_decode () works. The second parameter turns the result into an array:

 var_dump(json_decode('[{"a":"b"},{"c":"d"},{"e":"f"}]', true)); // gives array(3) { [0]=> array(1) { ["a"]=> string(1) "b" } [1]=> array(1) { ["c"]=> string(1) "d" } [2]=> array(1) { ["e"]=> string(1) "f" } } 
+19
source
 $array = '[{"a":"b"},{"c":"d"},{"e":"f"}]'; print_r(json_decode($array, true)); 

Read the manual - the parameters for the json_decode method json_decode clearly defined: http://www.php.net/manual/en/function.json-decode.php

+5
source

Source: https://habr.com/ru/post/1306269/


All Articles