Solved

Parsing json file with php

Posted on 2010-09-17
1
736 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

617 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