protected function RenderJSON($var, $callback = "",$useSimpleObject = false, $options = null, $forceUTF8 = 0)
	{
		$obj = null;

		if (is_a($var,'DataSet') || is_a($var,'DataPage'))
		{
			// if a dataset or datapage can be converted directly into an array without enumerating twice
			$obj = $var->ToObjectArray($useSimpleObject,$options);
		}
		else if ($useSimpleObject)
		{
			// we need to figure out what type
			if (is_array($var) || is_a($var,'SplFixedArray')  )
			{
				$obj = array();
				foreach ($var as $item)
				{
					$obj[] = $item->ToObject($options);
				}
			}
			elseif (is_a($var,'Phreezable') || is_a($var,'Reporter'))
			{
				$obj = $var->ToObject($options);
			}
			else
			{
				throw new Exception('RenderJSON could not determine the type of object to render');
			}
		}
		else
		{
			$obj = $var;
		}

		if ($forceUTF8 == 1) $this->UTF8Encode($obj);

		try
		{
			$output = json_encode($obj);
		}
		catch (Exception $ex)
		{
			if (strpos($ex->getMessage(),'Invalid UTF-8') !== false)
			{
				// a UTF encoding problem has been encountered
				if ($forceUTF8 == 2) 
				{
					$this->UTF8Encode($obj);
					$output = json_encode($obj);
				}
				else
				{
					throw new Exception('The object to be encoded contains invalid UTF-8 data.  Please verify your database character encoding or alternatively set the Controller::RenderJSON $forceUTF8 parameter to 1 or 2.');
				}
			}
			else
			{
				// we don't know what this is so don't try to handle it here
				throw $ex;
			}
		}

		if ($callback) $output = "$callback(" . $output . ")";

		// capture output instead of rendering if specified
		if ($this->CaptureOutputMode)
		{
			$this->DebugOutput = $output;
		}
		else
		{
			@header($callback ? 'Content-type: text/plain' : 'Content-type: application/json');
			print $output;
		}
	}
protected function RenderJSON($var, $callback = "",$useSimpleObject = false, $options = null, $forceUTF8 = 0)
	{
		$obj = null;

		if (is_a($var,'DataSet') || is_a($var,'DataPage'))
		{
			// if a dataset or datapage can be converted directly into an array without enumerating twice
			$obj = $var->ToObjectArray($useSimpleObject,$options);
		}
		else if ($useSimpleObject)
		{
			// we need to figure out what type
			if (is_array($var) || is_a($var,'SplFixedArray')  )
			{
				$obj = array();
				foreach ($var as $item)
				{
					$obj[] = $item->ToObject($options);
				}
			}
			elseif (is_a($var,'Phreezable') || is_a($var,'Reporter'))
			{
				$obj = $var->ToObject($options);
			}
			else
			{
				throw new Exception('RenderJSON could not determine the type of object to render');
			}
		}
		else
		{
			$obj = $var;
		}

		if ($forceUTF8 == 1) $this->UTF8Encode($obj);

		try
		{
			$output = json_encode($obj);
		}
		catch (Exception $ex)
		{
			if (strpos($ex->getMessage(),'Invalid UTF-8') !== false)
			{
				// a UTF encoding problem has been encountered
				if ($forceUTF8 == 2) 
				{
					$this->UTF8Encode($obj);
					$output = json_encode($obj);
				}
				else
				{
					throw new Exception('The object to be encoded contains invalid UTF-8 data.  Please verify your database character encoding or alternatively set the Controller::RenderJSON $forceUTF8 parameter to 1 or 2.');
				}
			}
			else
			{
				// we don't know what this is so don't try to handle it here
				throw $ex;
			}
		}

		if ($callback) $output = "$callback(" . $output . ")";

		// capture output instead of rendering if specified
		if ($this->CaptureOutputMode)
		{
			$this->DebugOutput = $output;
		}
		else
		{
			@header($callback ? 'Content-type: text/plain' : 'Content-type: application/json');
			print $output;
		}
	}
protected function RenderJSON ( $ var , $ callback = "" , $ useSimpleObject = false , $ options = null , $ forceUTF8 = 0 ) { $ obj = null ; if ( is_a ( $ var , 'DataSet' ) || is_a ( $ var , 'DataPage' ) ) { // if a dataset or datapage can be converted directly into an array without enumerating twice
 $ obj = $ var -> ToObjectArray ( $ useSimpleObject , $ options ) ; } else if ( $ useSimpleObject ) { // we need to figure out what type
 if ( is_array ( $ var ) || is_a ( $ var , 'SplFixedArray' ) ) { $ obj = array ( ) ; foreach ( $ var as $ item ) { $ obj [ ] = $ item -> ToObject ( $ options ) ; } } elseif ( is_a ( $ var , 'Phreezable' ) || is_a ( $ var , 'Reporter' ) ) { $ obj = $ var -> ToObject ( $ options ) ; } else { throw new Exception ( 'RenderJSON could not determine the type of object to render' ) ; } } else { $ obj = $ var ; } if ( $ forceUTF8 == 1 ) $ this -> UTF8Encode ( $ obj ) ; try { $ output = json_encode ( $ obj ) ; } catch ( Exception $ ex ) { if ( strpos ( $ ex -> getMessage ( ) , 'Invalid UTF-8' ) !== false ) { // a UTF encoding problem has been encountered
 if ( $ forceUTF8 == 2 ) { $ this -> UTF8Encode ( $ obj ) ; $ output = json_encode ( $ obj ) ; } else { throw new Exception ( 'The object to be encoded contains invalid UTF-8 data.  Please verify your database character encoding or alternatively set the Controller::RenderJSON $forceUTF8 parameter to 1 or 2.' ) ; } } else { // we don't know what this is so don't try to handle it here
 throw $ ex ; } } if ( $ callback ) $ output = "$callback(" . $ output . ")" ; // capture output instead of rendering if specified
 if ( $ this -> CaptureOutputMode ) { $ this -> DebugOutput = $ output ; } else { @ header ( $ callback ? 'Content-type: text/plain' : 'Content-type: application/json' ) ; print $ output ; } }
Renders the given value as JSON

@param variant the variable, array, object, etc to be rendered as JSON
@param string if a callback is provided, this will be rendered as JSONP
@param bool if true then objects will be returned ->GetObject() (only supports ObjectArray or individual Phreezable or Reporter object)
@param array  (only relvant if useSimpleObject is true) options array passed through to Phreezable->ToString()
@param bool set to 0 to leave data untouched.  set to 1 to always force value to UTF8. set to 2 to only force UTF8 if an encoding error occurs (WARNING: options 1 or 2 will likely result in unreadable characters.  The recommended fix is to set your database charset to utf8)
Renders the given value as JSON