Solved

Parsing json file with php

Posted on 2010-09-17
1
729 Views
Last Modified: 2012-05-10
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
Comment
Question by:jfsedlar3rd
1 Comment
 

Accepted Solution

by:
jfsedlar3rd earned 0 total points
ID: 33705710
 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now