![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
13/08/2014, 09:42
|
| | Fecha de Ingreso: julio-2012
Mensajes: 18
Antigüedad: 12 años, 6 meses Puntos: 0 | |
Recorrer JSON con PHP Hola buen día amigos y colegas:
Necesito por favor de su apoyo para resolver un problema que tengo.
La siguiente estructura JSON necesito recorrerla y almacenarla en una base de datos mysql.
La verdad he intentado recorrerla pero no he tenido éxito.
Código:
[{
"id": 254,
"name": "Prueba JSON",
"puntuaje": 10,
"link": "ejemplojason.com",
"type": [
"pagina_web",
"ocio",
"programacion",
"php"
],
"versions": [
{
"id": 255,
"type": [
"lang_ingles",
"app",
"v1"
],
"label": "version app ingles"
},
{
"id": 256,
"type": [
"lang_espanol",
"app",
"v2"
],
"label": "version app espanol"
},
{
"id": 257,
"type": [
"lang_jap",
"app",
"v3"
],
"label": "version app japones"
}
],
"info": {
"Sitio web",
"autor": "man, dude, jhon",
"country": "Estados Unidos",
"genre": [
"ocio"
],
"rating": "5",
"year": "2014"
},
"attributes": [
"lang_ingles",
"v1",
"v3",
"lang_espanol"
]
},
{
"id": 300,
"name": "Prueba JSON 2",
"puntuaje": 1,
"link": "ejemplojason2.com",
"type": [
"app",
"ocio",
"programacion",
"php"
],
"versions": [
{
"id": 301,
"type": [
"lang_ingles",
"app",
"v2"
],
"label": "version app ingles"
},
{
"id": 302,
"type": [
"lang_espanol",
"app",
"v3"
],
"label": "version app espanol"
},
{
"id": 303,
"type": [
"lang_jap",
"app",
"v4"
],
"label": "version app japones"
}
],
"info": {
"Sitio web",
"autor": "man, dude, jhon",
"country": "Estados Unidos",
"genre": [
"ocio"
],
"rating": "15",
"year": "2014"
},
"attributes": [
"lang_ingles",
"v1",
"v3",
"lang_espanol"
]
}
]
he intentado recorrerlo de esta forma: Código PHP: $json = file_get_contents('ejemplo.json'");
$obj = json_decode($json, true);
foreach ($obj as $key => $value)
{
echo "$key| $value";
foreach ($value as $k => $v)
{
echo "$k | $v <br />";
}
}
Pero tengo errores como: Warning: Invalid argument supplied for foreach() Notice: Array to string conversion in
Que se que es por que cuando recorro el JSON se topa con valores que terminan siendo arreglos.
De antemano agradezco mucho su atención y tiempo. Gracias.. Saludos.. |