Passing multiple array to drupal_json_output() is not giving correct output in jquery ajax Passing multiple array to drupal_json_output() is not giving correct output in jquery ajax.

I am using a menu_callback function and returning a multiple array like 

function test_callback() {
   for($i = 0; $i &lt; 10; $i++) {
    $arr = array('message' =&gt; 'test'.$i, 'data' =&gt; 'data'.$i);
    $arrs[] = $arr;
   }
 drupal_json_output($arrs);
}


Now, in the jquery, I wrote like this,

$.ajax({
url: the above url,
dataType: 'json',
success: function(data) {
$(data).each(function(key,val) {
  console.log(val.message);
});
})
});


The output in the console is giving an object.

I tried to use $.each for the val also, but the output it is returning as undefined. I tried in a lot of ways using $.get etc. but not getting the output. Can anyone help me here??
To setup a service which returns a json formatted data, you should set the delivery callback to drupal_json_output. This will only output the service data and not all the HTML defined in your theme.

For example

function YOURMODULE_menu()
{
    $items = array();

    $items['service/ajax'] = array(
        'title' =&gt; t('Ajax service'),
        'page callback' =&gt; 'YOURMODULE_ajax',
        'delivery callback' =&gt; 'drupal_json_output',
        'access arguments' =&gt; array('access content'),
        'type' =&gt; MENU_CALLBACK,
    );

    return $items;
}

function YOURMODULE_ajax()
{
    for($i = 0; $i &lt; 10; $i++) {
        $arr = array('message' =&gt; 'test'.$i, 'data' =&gt; 'data'.$i);
        $arrs[] = $arr;
    }

    return $arrs;
}