I need to retrieve the result of a view and encode it in json after. By doing this, it shows me 'Array' but not the content. Could you tell me where I'm wrong? thank you a lot!
function web_service_expositions($viewname, $display_id = NULL, $args = NULL) {
$view = views_get_view('expositions_now');
if (is_object($view)) {
if (is_array($args)) {
$view->set_arguments($args);
}
if (is_string($display_id)) {
$view->set_display($display_id);
}
else {
$view->init_display();
}
$view->pre_execute();
$view->execute();
/* print "<pre> $viewname: $display_id";
print_r(get_class_methods($view)); */
return $view->result;
}
else {
return t('View %viewname not found.', array('%viewname' => $viewname));
}
}
try replacing
return $view->result;
with
drupal_json_output($view->result);
drupal_exit();
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_json_output/7
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.