Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i am trying to do an application and I have an array multidimensional that I create with Javascript, throught JSON, and I want to update a DB with the information in that array. The problem comes when I try to cast the string to array using json_decode. When I use only a few words to load the array it cast good but if I use large strings, it doesn't work, and say that the type of the variable is null...

In Html (dict is the array that I fill with different information):

var stri= JSON.stringify(dict);
      document.getElementById("hiddenF").value = stri;


<form action="actualizar_base_datos.php" method="post">
        <button type="submit" id="botonBaseDatos" name="botonBaseDatos" style="margin: 5px; visibility:hidden; background-color:lightgreen; float: right;" onclick="probamos()" >Guardar todo</button>              
        <input type="hidden" id="hiddenF" name="hiddenF" value="">
        <input id="contar" name="contar" type="hidden" value="">
        </form>

In php file:

$jArray = $_POST['hiddenF'];
$num = $_POST['contar'];
echo $num."<br>";
$pru=json_decode($jArray,true);
var_dump($pru);
echo gettype($pru);
$ase= $pru['titulo'];
for($i=0;$i<$num;$i++)
{
$pr=$i+1;
echo "Momento".($pr);
echo $ase[$i];
echo "<br>";
}

One of the samples of my JSON

{
    "titulo": {
        "0": "rfdsfs"
    },
    "calle": {
        "0": "2857 Lagoon Road, Charlton Nueva Gales del Sur 2795, Australia"
    },
    "longitud": {
        "0": "-33.692547"
    },
    "latitud": {
        "0": "149.609283"
    },
    "comentarios": {
        "0": "A ese proceso de institucionalización, siguió la especialización y subdivisión de la disciplina con diferentes sesgos temporales (de cuestionable aplicación fuera de la civilización occidental: historia antigua, medieval, moderna, contemporánea -estas dos últimas, habituales en la historiografía francesa o española, no suelen subdividirse en la historiografía anglosajona: en:modern era-), espaciales (historia nacional, regional, local, continental -de África, de Asia, de América, de Europa, de Oceanía-), temáticos (historia política, militar, de las instituciones, económica y social, de los movimientos sociales y de los movimientos políticos, de las civilizaciones, de las mujeres, de la vida cotidiana, de las mentalidades, de las ideas, cultural), historias sectoriales ligadas a otras disciplinas (historia del arte, de la música, de las religiones, del derecho, de la ciencia, de la medicina, de la economía, de la ciencia política, de las doctrinas políticas, de la tecnología), o centrada en cualquier tipo de cuestión particular (historia de la electricidad, de la democracia, de la Iglesia, de los sindicatos, de los sistemas operativos, de las formas -literarias de la Biblia-, etc). Ante la atomización del campo de estudio, también se han realizado distintas propuestas que consideran la necesidad de superar esas subdivisiones con la búsqu"
    }
}

Thanks guys.

share|improve this question
    
NULL is returned if the json cannot be decoded or if the encoded data is deeper than the recursion limit. Source: php.net/manual/en/… –  RainFromHeaven Sep 19 '13 at 17:01
    
but then how have I to decode this json in php? And how I can know the deeper of encoded data? –  kartGIS Sep 19 '13 at 20:00
    
How long is your string? –  RainFromHeaven Sep 19 '13 at 20:21
    
depends on the user.. can be large as 800 character –  kartGIS Sep 19 '13 at 21:33
    
I think this is an encoding issue. You should ensure that your string is properly encoded as UTF-8. –  RainFromHeaven Sep 19 '13 at 21:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.