src/Suki/Tools.php
public function jsonResponse($data = [])
	{
		global $db_show_debug;

		$json = '';
		$result = false;

		// Defensive programming anyone?
		if (empty($data))
			return false;

		// This is pretty simply, just encode the supplied data and be done with it.
		$json = json_encode($data);

		$result = json_last_error() == JSON_ERROR_NONE;

		if ($result)
		{
			// Don't need extra stuff...
			$db_show_debug = false;

			// Kill anything else
			ob_end_clean();

			if ($this->_app->modSetting('CompressedOutput'))
				@ob_start('ob_gzhandler');

			else
				ob_start();

			// Set the header.
			header('Content-Type: application/json');

			// Echo!
			echo $json;

			// Done
			obExit(false);
		}

		return $result;
	}
public function jsonResponse($data = [])
	{
		global $db_show_debug;

		$json = '';
		$result = false;

		// Defensive programming anyone?
		if (empty($data))
			return false;

		// This is pretty simply, just encode the supplied data and be done with it.
		$json = json_encode($data);

		$result = json_last_error() == JSON_ERROR_NONE;

		if ($result)
		{
			// Don't need extra stuff...
			$db_show_debug = false;

			// Kill anything else
			ob_end_clean();

			if ($this->_app->modSetting('CompressedOutput'))
				@ob_start('ob_gzhandler');

			else
				ob_start();

			// Set the header.
			header('Content-Type: application/json');

			// Echo!
			echo $json;

			// Done
			obExit(false);
		}

		return $result;
	}
public function jsonResponse ( $ data = [ ] ) { global $ db_show_debug ; $ json = '' ; $ result = false ; // Defensive programming anyone? if ( empty ( $ data ) ) return false ; // This is pretty simply, just encode the supplied data and be done with it. $ json = json_encode ( $ data ) ; $ result = json_last_error ( ) == JSON_ERROR_NONE ; if ( $ result ) { // Don't need extra stuff... $ db_show_debug = false ; // Kill anything else ob_end_clean ( ) ; if ( $ this -> _app -> modSetting ( 'CompressedOutput' ) ) @ ob_start ( 'ob_gzhandler' ) ; else ob_start ( ) ; // Set the header. header ( 'Content-Type: application/json' ) ; // Echo! echo $ json ; // Done obExit ( false ) ; } return $ result ; }
Outputs a json encoded string
It assumes the data is a valid array.
@param array $data The data to be converted, needs to be an array
@access public
@return boolean whether or not the data was encoded and outputted
Outputs a json encoded string It assumes the data is a valid array .