How do I parse the fcttext from each "period" in json using PHP

  • 1
  • Question
  • Updated 5 years ago
I figured out how to parse all the json conditions and display them in PHP, but the forecast json has further subdivisions that I don't know how to access through the parse line. An example code line to get the forecast for period:0 (assuming period:1, etc., would thereby be obvious) would be very helpful. Thanks.
Photo of richardgmills

richardgmills

  • 3 Posts
  • 0 Reply Likes

Posted 5 years ago

  • 1
Photo of richardgmills

richardgmills

  • 3 Posts
  • 0 Reply Likes
It seems like it should be:

$forecast = $parsed_json->{'forecast'}->{'txt_forecast'}->{'forecastday[0].fcttext'};

...but echo $forecast gives nothing, and I've tried various alterations of the above.
Photo of richardgmills

richardgmills

  • 3 Posts
  • 0 Reply Likes
Figured it out:

$forecast = $parsed_json->{'forecast'}->{'txt_forecast'}->{'forecastday'}[0]->{'fcttext'};