If a JSON string has spaces in its name "Some Items" (is there a more accurate term for this?), how do you access it in PHP after using json_decode($json_string) on it? Is this name even required for data returned from an API?
JSON String
{"Some Items":[{"post_id":"1284"},{"post_id":"1392"},{"post_id":"1349"}]}
These doesn’t work
$data = json_decode($json_string);
$data = $data->"Some Items"; // invalid PHP
$data = $data["Some Items"]; // Cannot use object of type stdClass as array
If you don’t like the curly braces idea you can use the dynamic accessor business:
Or, you could cast $data to an array and use the square brackets:
json_decodehas a switch so you don’t need to use casting.