Ver Mensaje Individual
  #2 (permalink)  
Antiguo 10/02/2009, 09:19
Avatar de Panino5001
Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años, 9 meses
Puntos: 834
Respuesta: de Javascript a JSON

Fijate si te sirve algo así:
Código php:
Ver original
  1. <?php
  2. if(isset($_GET['algo'])){
  3.     $v=json_decode($_GET['algo'],true);
  4.     print_r($v);
  5.     exit;
  6. }
  7. ?>
  8. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  9. <html xmlns="http://www.w3.org/1999/xhtml">
  10. <head>
  11. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  12. <title>Documento sin t&iacute;tulo</title>
  13. <script>
  14. var objeto = {nivel:'A', nombre:'Costa Sur', personal:'145',algo:{pepe:123},otro:['a','b']};
  15. function print_JS(){
  16.     this.a='';
  17.     this.recorrer=function(o){
  18.         if(o.constructor==Array)
  19.                this.a+='[';
  20.         if(o.constructor==Object)
  21.             this.a+='{';
  22.         for(var i in o){
  23.             if(o.constructor!=Array)
  24.                 this.a+='"'+i+'":';
  25.             if(o[i].constructor==Object){
  26.                    this.recorrer(o[i]);
  27.             }else if(o[i].constructor==Array){
  28.                 this.recorrer(o[i]);
  29.             }else if(o[i].constructor==String){
  30.                 this.a+='"'+o[i]+'",';
  31.             }else{
  32.                 this.a+=o[i]+',';
  33.             }
  34.         }
  35.         if(o.constructor==Object)
  36.             this.a+='},';
  37.         if(o.constructor==Array)
  38.             this.a+='],';
  39.         return this.a.substr(0,this.a.length-1).split(',}').join('}').split(',]').join(']');
  40.     }
  41. }
  42. onload=function(){
  43.     var r=new print_JS();
  44.     document.getElementById('algo').value=r.recorrer(objeto);
  45. }
  46. </script>
  47. </head>
  48. <body>
  49. <form name="form1" method="get" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  50.   <textarea name="algo" rows="5" id="algo"></textarea>
  51.   <input type="submit" name="Submit" value="Enviar">
  52. </form>
  53. </body>
  54. </html>