$DecodedJson= json_decode($JsonData, TRUE);
if (!is_null($DecodedJson))
{
echo "Json Value1: " . $DecodedJson[0]['trends'];
echo "<br><br>";
print_r($DecodedJson);
}
Check for json values present
$DecodedJson = json_decode($result, TRUE);
if (!is_null($DecodedJson))
{
if (isset($DecodedJson['data']))
echo $DecodedJson['data'];
if (isset($DecodedJson['result'][0]['longitude']))
echo $DecodedJson['result'][0]['longitude'];
}
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.