Foros del Web » Programando para Internet » PHP »

Extraer datos de json con PHP

Estas en el tema de Extraer datos de json con PHP en el foro de PHP en Foros del Web. Necesito extraer de un json que tiene la siguiente estructura, period 0, period 1 los nombres de icon y luego de day 14 las conditions, ...
  #1 (permalink)  
Antiguo 14/01/2014, 17:36
 
Fecha de Ingreso: noviembre-2012
Mensajes: 54
Antigüedad: 11 años, 5 meses
Puntos: 0
Extraer datos de json con PHP

Necesito extraer de un json que tiene la siguiente estructura, period 0, period 1 los nombres de icon y luego de day 14 las conditions,

Como podria hacerlo tengo el siguiente php, pero no lo consigo, estoy probando con icon.

$json_string = file_get_contents("http://.json");
$parsed_json = json_decode($json_string);
$temp_c = $parsed_json->{'forecast'}->{'forecastday'}->{'icon'};

?>


<?php


echo $temp_c;




?>



//JSON


{
"response": {
"version":"0.1",
"termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
"features": {
"forecast": 1
}
}
,
"forecast":{
"txt_forecast": {
"date":"10:00 AM UYST",
"forecastday": [
{
"period":0,
"icon":"partlycloudy",
"icon_url":"http://icons-ak.wxug.com/i/c/k/partlycloudy.gif",
"title":"Tuesday",
"fcttext":"Partly cloudy. Fog early. High of 82F. Winds from the ESE at 5 to 15 mph.",
"fcttext_metric":"Partly cloudy. Fog early. High of 28C. Winds from the ESE at 5 to 20 km/h.",
"pop":"0"
}
,
{
"period":1,
"icon":"clear",
"icon_url":"http://icons-ak.wxug.com/i/c/k/clear.gif",
"title":"Tuesday Night",
"fcttext":"Partly cloudy in the evening, then clear. Low of 63F. Winds from the ESE at 5 to 15 mph shifting to the NNE after midnight.",
"fcttext_metric":"Partly cloudy in the evening, then clear. Low of 17C. Breezy. Winds from the ESE at 10 to 20 km/h shifting to the NNE after midnight.",
"pop":"0"
}
,
{
"period":2,
"icon":"partlycloudy",
"icon_url":"http://icons-ak.wxug.com/i/c/k/partlycloudy.gif",
"title":"Wednesday",
"fcttext":"Partly cloudy. Fog early. High of 86F. Winds from the NW at 5 to 10 mph shifting to the SW in the afternoon.",
"fcttext_metric":"Partly cloudy. Fog early. High of 30C. Winds from the NW at 10 to 15 km/h shifting to the SW in the afternoon.",
"pop":"0"
}
,
{
"period":3,
"icon":"chancerain",
"icon_url":"http://icons-ak.wxug.com/i/c/k/chancerain.gif",
"title":"Wednesday Night",
"fcttext":"Partly cloudy with a chance of rain. Low of 66F. Winds from the East at 5 to 10 mph. Chance of rain 50%.",
"fcttext_metric":"Partly cloudy with a chance of rain. Low of 19C. Winds from the East at 10 to 15 km/h. Chance of rain 50%.",
"pop":"50"
}
,
{
"period":4,
"icon":"partlycloudy",
"icon_url":"http://icons-ak.wxug.com/i/c/k/partlycloudy.gif",
"title":"Thursday",
"fcttext":"Partly cloudy. High of 90F. Winds from the NE at 5 to 10 mph shifting to the ESE in the afternoon.",
"fcttext_metric":"Partly cloudy. High of 32C. Winds from the NE at 10 to 15 km/h shifting to the ESE in the afternoon.",
"pop":"0"
}
,
{
"period":5,
"icon":"partlycloudy",
"icon_url":"http://icons-ak.wxug.com/i/c/k/partlycloudy.gif",
"title":"Thursday Night",
"fcttext":"Partly cloudy. Low of 72F. Breezy. Winds from the East at 10 to 20 mph shifting to the NNE after midnight.",
"fcttext_metric":"Partly cloudy. Low of 22C. Breezy. Winds from the East at 15 to 30 km/h shifting to the NNE after midnight.",
"pop":"0"
}
,
{
"period":6,
"icon":"partlycloudy",
"icon_url":"http://icons-ak.wxug.com/i/c/k/partlycloudy.gif",
"title":"Friday",
"fcttext":"Mostly cloudy. High of 93F. Winds from the NW at 10 to 15 mph.",
"fcttext_metric":"Mostly cloudy. High of 34C. Breezy. Winds from the NW at 15 to 25 km/h.",
"pop":"0"
}
,
{
"period":7,
"icon":"partlycloudy",
"icon_url":"http://icons-ak.wxug.com/i/c/k/partlycloudy.gif",
"title":"Friday Night",
"fcttext":"Partly cloudy in the evening, then overcast. Low of 75F. Winds from the North at 5 to 15 mph.",
"fcttext_metric":"Partly cloudy in the evening, then overcast. Low of 24C. Breezy. Winds from the North at 10 to 25 km/h.",
"pop":"0"
}
]
},
"simpleforecast": {
"forecastday": [
{"date":{
"epoch":"1389744000",
"pretty":"10:00 PM UYST on January 14, 2014",
"day":14,
"month":1,
"year":2014,
"yday":13,
"hour":22,
"min":"00",
"sec":0,
"isdst":"1",
"monthname":"January",
"monthname_short":"Jan",
"weekday_short":"Tue",
"weekday":"Tuesday",
"ampm":"PM",
"tz_short":"UYST",
"tz_long":"America/Montevideo"
},
"period":1,
"high": {
"fahrenheit":"82",
"celsius":"28"
},
"low": {
"fahrenheit":"63",
"celsius":"17"
},
"conditions":"Partly Cloudy",
"icon":"partlycloudy",
"icon_url":"http://icons-ak.wxug.com/i/c/k/partlycloudy.gif",
"skyicon":"partlycloudy",
"pop":0,
"qpf_allday": {
"in": 0.00,
"mm": 0.0
},
"qpf_day": {
"in": 0.00,
"mm": 0.0
},
"qpf_night": {
"in": 0.00,
"mm": 0.0
},
"snow_allday": {
"in": 0,
"cm": 0
},
"snow_day": {
"in": 0,
"cm": 0
},
"snow_night": {
"in": 0,
"cm": 0
},
"maxwind": {
"mph": 11,
"kph": 18,
"dir": "SE",
"degrees": 127
},
"avewind": {
"mph": 9,
"kph": 14,
"dir": "ESE",
"degrees": 117
},
"avehumidity": 68,
"maxhumidity": 98,
"minhumidity": 58
}

Etiquetas: html, json
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:38.