Ver Mensaje Individual
  #10 (permalink)  
Antiguo 21/05/2016, 02:54
primary
 
Fecha de Ingreso: agosto-2011
Mensajes: 306
Antigüedad: 12 años, 8 meses
Puntos: 5
Respuesta: crear archivo json con este formato

Hola no lo consigo probe asi:

Código PHP:
Ver original
  1. $JSON["cols"][0]=array('id'=>'','label'=>'estado','pattern'=>'','type'=>'string');
  2. $JSON["cols"][1]=array('id'=>'','label'=>'cantidad1','pattern'=>'','type'=>'number');
  3. $JSON["cols"][2]=array('id'=>'','label'=>'cantidad2','pattern'=>'','type'=>'number');
  4.                            
  5. while($row=$pdo->fetch()){
  6.     $estado=$row["estado"];
  7.         $num1=$row["cantidad1"];
  8.         $num2=$row["cantidad2"];
  9.         $JSON["rows"][]=array('c'=>array('v'=>'$estado'));
  10.         $JSON["rows"][]=array('c'=>array('v'=>'$num1'));
  11.         $JSON["rows"][]=array('c'=>array('v'=>'$num2'));
  12. }
  13.  
  14. $string = json_encode($JSON);
  15. echo $string;
  16. /*
  17. {
  18.         "cols":[
  19.               {"id":"","label":"estado","pattern":"","type":"string"},
  20.               {"id":"","label":"cantidad1","pattern":"","type":"number"},
  21.               {"id":"","label":"cantidad2","pattern":"","type":"number"}
  22.          ],
  23.          
  24.          "rows":[
  25.               {"c":{"v":"soltero"}},{"c":{"v":"200"}},{"c":{"v":"100"}},
  26.               {"c":{"v":"casado"}},{"c":{"v":"20"}},{"c":{"v":"16"}},
  27.               {"c":{"v":"divorciado"}},{"c":{"v":"209"}},{"c":{"v":"20"}}
  28.          ]
  29.              
  30. }
  31.  
  32. */

el cols se me estructura como quiero pero con el rows no lo consigo alguien me puede ayudar?
saludos