Ver Mensaje Individual
  #3 (permalink)  
Antiguo 17/08/2015, 09:44
PSPforever
 
Fecha de Ingreso: marzo-2008
Mensajes: 186
Antigüedad: 16 años, 1 mes
Puntos: 3
Respuesta: Problema para crear un JSON

Ahora lo he cambiado de esta manera:
Código PHP:
Ver original
  1. <?php
  2. //sleep(5);
  3. header('Content-Type: application/json');
  4.  
  5. $path = $_SERVER['DOCUMENT_ROOT']."/cms/img/";
  6.  
  7.     $dir = opendir($path);
  8.    
  9.     while ($archivo = readdir($dir)) {
  10.  
  11.         if ( $archivo != '.' && $archivo != '..' && $archivo != 'loader.gif') {
  12.  
  13.             $datos = array("nombre" => $archivo);
  14.  
  15.             echo json_encode($datos);
  16.                
  17.         }
  18.    
  19.     }
  20. ?>

Y en pantalla imprime :
Código JSON:
Ver original
  1. {"nombre":"asturias"}
  2. {"nombre":"navarra"}
  3. {"nombre":"tenerife"}

Pero me falta añadir la coma al final. Por ej. {nombre:asturias}, ¿Cómo puedo añadirla?