Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 746
  • Last Modified:

Parsing json file with php

I need some help parsing this json file using php. I am a .NET programmer and i am a novice with php.

I was able to access some of the contents using:

$json = file_get_contents('')
$obj = json_decode($json,true);
$type = $obj->{'predominantType'};

The content i am having trouble with is the "dayList" array.

how can i access each day in a loop and set the data to a variable?
{"city":"Flint","dayList":[{"dateTime":1284681600000,"desc":"The amount of pollen in the air for Friday will be higher than they were on Thursday in the moderate range. This increase is due to drier air. If you do suffer from allergies Friday could be more difficult.","level":5.1},{"dateTime":1284768000000,"desc":"The amount of pollen in the air for Saturday will not change appreciably and will remain in the moderate range. This is a result of stable temperatures. This lack of change in airborne pollen will continue to affect those who suffer from allergies and those who live with the allergy sufferers.","level":5},{"dateTime":1284854400000,"desc":null,"level":2.8},{"dateTime":1284940800000,"desc":null,"level":3.2},{"dateTime":1285027200000,"desc":null,"level":4.3}],"predominantType":"Ragweed, Chenopods and Nettle.","state":"MI"}

Open in new window

0
jfsedlar3rd
Asked:
jfsedlar3rd
1 Solution
 
jfsedlar3rdAuthor Commented:
 echo "Predominant Type: " . $var_dump['predominantType'] . "</br>";

  foreach ($var_dump['dayList'] As $value)
  {
   echo "Date: " . $value['dateTime'] . "</br>";
   echo "Level: " . $value['level'] . "</br>";

  }
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now