I have a sample code:
$description = '{"2G Network":"GSM 850 / 900 / 1800 / 1900 ","3G Network":"HSDPA 850 / 900 / 1700 / 1900 / 2100 "}';
$data = json_decode($description);
echo $data->2G Network;
// OR echo $data['2G Network'];
result is error, how to fix it !
Try this:
The problem wasn't with JSON, but that you had a space in the object property you were trying to access. If you use curly braces
{
}
, then you can use strings to name the property you want to get/set.Brad solution is perfect, and if you want similar from an array you can do it like:
you may call functions to remove the spaces in the JSON
see below http://www.pukkared.com/2010/02/removing-extra-white-space-before-returning-json-data/
You can either remove the space between 2G and Network or decode the json to an array using
json_decode($description, true)