You are here

function _views_json_json_encode in Views Datasource 7

Backwards-compatible JSON encoder.

Provides backwars-compatible support for more JSON encoding formats. Uses PHP's native JSON encoding when PHP 5.3.0 or greater is detected. Fallbacks to manual encoding/escaping when PHP 5.2.x and below is detected.

Parameters

array $rows: Results from template_preprocess_views_views_json_style_simple().

int $bitmask: Integer to use as the $bitmask parameter for json_encode().

2 calls to _views_json_json_encode()
views-views-json-style-simple-object.tpl.php in views/theme/views-views-json-style-simple-object.tpl.php
views-views-json-style-simple.tpl.php in views/theme/views-views-json-style-simple.tpl.php

File

./views_json.module, line 489

Code

function _views_json_json_encode($rows, $bitmask = NULL) {
  if (defined('PHP_MAJOR_VERSION') && PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3) {
    $json = json_encode($rows, $bitmask);

    // Encoding features not supported before 5.4.x.
    if (PHP_MINOR_VERSION <= 4) {
      $json = str_replace(array(
        '\\/',
      ), array(
        '/',
      ), $json);
    }
  }
  else {
    $json = json_encode($rows);

    // Fix for issue #1613344.
    $json = str_replace(array(
      '\\/',
    ), array(
      '/',
    ), $json);
  }
  return $json;
}