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;
		}
	}