带有JSON的DataTable数据集

I'm trying to use DataTable to show all fields of my JSON, but I'm not understand how to use it.

I just need how to populate dataset correctly to read data.

<script>
        <?php
            var jqxhr = $.ajax({url: api_ricerca_ingredienti, type: "GET",dataType: "json", data: {all: 1, ln : "it",completo:"-1",conteggio: 1}} )
              var max=json.items.length;
              for (i=0;i<max;i++){
                var el=json.items[i];
              }
              $(".risultato_ricerca").click(function() {
                carica_ingrediente($(this).attr('data-id'));
              });
            })
            <?php }?>

            var dataSet = [
              /*HOW?*/
            ];

            $(document).ready(function() {
              $('#example').DataTable( {
                data: dataSet,
                columns: [
                  { title: "Nome" },
                  { title: "Stato" },
                  { title: "Home" },
                  { title: "Utente" },
                  { title: "Mi piace" },
                  { title: "Contributi" }
                ]
              } );
            } );
            </script>
            <table id="example" class="table table-responsive table-hover table-dynamic filter-head"></table>

First, two comments about your code. As @Patrick Q stated, your PHP tags are useless: you are writing Javascript, PHP is another things that has nothing to do with your code, so remove <?php and <?php }?>

Then, i can't understand this code:

for (i=0;i<max;i++){
   var el=json.items[i];
}

This for is completely useless. you cycle through every element in json.items without performing any operation. At the end you just store the last json.items in the el (without even using el in your code).

By the way, your main question: As said in the official documentation, your dataSet must contain an array for every row of your table in the format:

var dataSet = [
    ["john","italy","home","john",15,20],
    ["john","italy","home","john",15,20]
]

This example will create two identical rows with random data inside.

Assuming every item in your json has name country home user likes contribs fields you will need something like that:

var dataSet = []; 
for (i=0;i<json.items.length;i++){
     var el = [json.items[i].name,json.items[i].country, json.items[i].home, json.items[i].user, json.items[i].likes, json.items[i].contribs]
     dataSet[i] = el;
 }

Sorry guys. I've truncated my prev code. Now the building of data array works like a charm. I've just a doubt about a console error: "jquery.dataTables.min.js:5 Uncaught TypeError: Cannot read property 'aDataSort' of undefined"

I can't show my rows. According with your opinion, what's the problem?

Thank you!

<script>
< ?php
if (isset($_GET) && isset($_GET['id'])){
             ?>
             $( document ).ready(function() {
               carica_ingrediente('<?php echo $_GET['id'];?>');
            });
          <?php }else {?>
            $('#query').keypress(function(e) {
              if (e.keyCode == $.ui.keyCode.ENTER) {
                $('#cerca').click();
              }
            });
          $(document).ready(function() {
              var jqxhr = $.ajax({url: api_ricerca_ingredienti, type:   "GET",dataType: "json", data: {all: 1, ln : "it",completo:"-1",conteggio: 1}} )
              .done(function(json) {
                if (json.res==0){
                  alert( "Inserisci una parola per iniziare la ricerca " );
                  return;
                }
                var dataSet = [];
                for (i=0;i<json.items.length;i++){
                  var el = [json.items[i].nome,json.items[i].completo, json.items[i].home, json.items[i].utente, json.items[i].likes, json.items[i].countingredienti];
                  dataSet[i] = el;
                  console.log(el);
                }
                $(".risultato_ricerca").click(function() {
                  carica_ingrediente($(this).attr('data-id'));
                });

                $(document).ready(function() {
                  $('#example').DataTable( {
                    data: dataSet,
                    columns: [
                      { title: "Nome" },
                      { title: "Stato" },
                      { title: "Home" },
                      { title: "Utente" },
                      { title: "Mi piace" },
                      { title: "Contributi" }
                    ]
                  } );
                } );
              })
              .fail(function() {
                alert( "error" );
              });

            });

            <?php }?>
            </script>