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

Check for json values present

  $decoded_json = json_decode($result, TRUE);
  if (
    ($decoded_json['status'] != 200) ||
    (empty($decoded_json['result'][0]['longitude'])) ||
    //----- 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);
		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.

We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


Your email address will not be published.