I'm frustrated

  • 1
  • Problem
  • Updated 6 years ago

I'm familiar with php but a complete newbie with json. When I cut and paste the following php example code from the API into this HTML document I get no output.
Actually...just executing the php alone doesn't work either.

I use Firefox...could there be an issue with my browser? I find it embarrassing to have to ask for help on what is probably a simple coding issue but I've really spent quite some time on this...



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml...>


$temp_f = $parsed_json->{'current_observation'}->{'temp_f'};
echo "Current temperature in ${location} is: ${temp_f}\n";

print 'leaving test';
Photo of Rudy J. Nickmann

Rudy J. Nickmann

  • 4 Posts
  • 0 Reply Likes

Posted 6 years ago

  • 1
Photo of AndyWu


  • 4 Posts
  • 0 Reply Likes
Hi Rudy,
What's the error code?
You might experience the same problem I had.
I just solved my problem.


Photo of vancew


  • 9 Posts
  • 0 Reply Likes
Personally I use the json_decode function with the assoc = true:

$json = json_decode($json_from_wxug, true)

This way I can access the $json var like any other assoc array, like so:

$temp_f = $json['current_observation']['temp_f'];

This also allows a cleaner print_r output IMO:

echo "<pre>";//pre is only required if you want to view it pretty in your browser
print_r($json);//outputs a nice to read, tabbed format
echo "</pre>";//pre tag is not required if you want to 'view source' with your browser

Hope that helps a little.