$JsonArray = json_decode($JsonData, TRUE);
  if (!is_null($JsonArray))
  {
    echo "Json Value1: " . $JsonArray[0]['trends'];
    echo "<br><br>";
    print_r($JsonArray);
  }

Check for json values present

  $decoded_json = json_decode($result, TRUE);
  if (
    ($decoded_json['status'] != 200) ||
    (empty($decoded_json['result'][0]['longitude'])) ||
    (empty($decoded_json['result'][0]['latitude']))
  )
  {
    //----- THERE WAS AN ERROR -----
    $output .= "ERROR";
  }

Reading json from a file

	if (is_file('found_wifi_networks.json'))
	{
		$file_contents = file_get_contents('found_wifi_networks.json');
		$decoded_json = json_decode($file_contents, TRUE);
		print_r($decoded_json);
		echo "<br /><br />";
		$results_count = count($decoded_json['FoundWiFiNetworks']);
		for ($count = 0; $count < $results_count; $count++)
		{
			echo "Result " . ($count + 1) . ": " . $decoded_json['FoundWiFiNetworks'][$count][SSID] . "<br />";
		}
		echo "<br /><br />";
	}

json stored within json fields

When you decode remember that you will need to decode the nested json field as a separate decode operation, you won’t get a single array which automatically nests the sub json.

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published.