Los datos JSON no se muestran

I am using data that's in a csv file to display it using JSON. I can see it in the alert, but not in the html. Also, I tried to create an associative array to make it easier to refer to through Jquery, but it's not being passed that way.

 if (($handle = fopen('upload/05-22-2012-1-43-28BEN-new.csv'. '', "r")) !== FALSE) {
       while (($row_array = fgetcsv($handle, 1024, ","))) {
            while ($val != '') {
                foreach ($row_array as $key => $val) {
                        $row_array[] = array_combine($key, trim(str_replace('"', '', $val)));
            $complete[] = $row_array;

        echo json_encode($complete);



      <div id="showdata"></div>



    $.getJSON('WF-XML.php', function(data) {
        alert(data); //uncomment this for debug
        //alert (data.item1+" "+data.item2+" "+data.item3); //further debug



preguntado el 22 de mayo de 12 a las 21:05

Por favor lea el documentos de jQuery for what argument type to pass into the html() method. -

Also, I have no idea why you call matriz_combinar with two strings. Do you? -

I was trying to create an associative array. -

Is $row_array not already associative, as you loop through it with a foreach-as-loop? -

1 Respuestas

First of all you need to stringify your object using JSON.stringify, also .html() method does not escape the string - try using .text() instead.

I've created a simple fiddle for testing - http://jsfiddle.net/E9KTy/

contestado el 22 de mayo de 12 a las 21:05

Thanks! Thank worked! How would I loop through the results and display them in an html formatted way? - MG1

Sorry, not sure what you mean. Could you please update your post and add an example JSON string that I can use for testing? - Serguéi Rybalkin

Also, my results are being displayed like this: [["11704","1611704","BENV1072"],["11703","1611703","BENV1073"]] Without the sqwiggled brackets. How would I refer to them in an array? - MG1

OK, so basically you have a two dimensions array and want to loop through the second dimension? If this is the case then check out the following example - jsfiddle.net/E9KTy/2 - Serguéi Rybalkin

What if I only wanted to print the data that's in the second position of the array? - MG1

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.