/** * Encodes the map or array provided earlier to the encoder into a JSON string and returns it. * * @return CUStringObject The resulting JSON string. */ public function encode() { assert('is_cmap($this->m_source) || is_carray($this->m_source)', vs(isset($this), get_defined_vars())); $source = $this->m_source; if (CDebug::assertionsLevel2()) { // Check character encodings in string values. self::recurseStringValidation($source, 0); } $source = self::recurseValueBeforeEncoding($source, 0); $options = 0; if (!$this->m_escapeNonAsciiChars) { $options |= JSON_UNESCAPED_UNICODE; } if (!$this->m_escapeForwardSlashes) { $options |= JSON_UNESCAPED_SLASHES; } if ($this->m_escapeAngleBrackets) { $options |= JSON_HEX_TAG; } if ($this->m_escapeAmpersands) { $options |= JSON_HEX_AMP; } if ($this->m_escapeSingleQuotes) { $options |= JSON_HEX_APOS; } if ($this->m_escapeDoubleQuotes) { $options |= JSON_HEX_QUOT; } if ($this->m_prettyPrint) { $options |= JSON_PRETTY_PRINT; } $encodedValue = json_encode($source, $options, self::$ms_maxRecursionDepth); assert('is_cstring($encodedValue) && !CString::isEmpty($encodedValue)', vs(isset($this), get_defined_vars())); return $encodedValue; }