Solved

Parsing json file with php

Posted on 2010-09-17
1
735 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

751 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