3 homepage: http://arc.semsol.org/
4 license: http://arc.semsol.org/license
6 class: ARC2 Legacy JSON Serializer
7 author: Benjamin Nowack
13 class ARC2_LegacyJSONSerializer extends ARC2_Class {
15 function __construct($a = '', &$caller) {
16 parent::__construct($a, $caller);
19 function ARC2_LegacyJSONSerializer($a = '', &$caller) {/* ns */
20 $this->__construct($a, $caller);
25 $this->content_header = 'application/json';
30 function getSerializedArray($struct, $ind = '') {
32 if (function_exists('json_encode')) return str_replace('","', '",' . $n . '"', json_encode($struct));
34 $from = array("\\", "\r", "\t", "\n", '"', "\b", "\f", "/");
35 $to = array('\\\\', '\r', '\t', '\n', '\"', '\b', '\f', '\/');
36 $is_flat = $this->isAssociativeArray($struct) ? 0 : 1;
37 foreach ($struct as $k => $v) {
38 $r .= $r ? ',' . $n . $ind . $ind : $ind . $ind;
39 $r .= $is_flat ? '' : '"' . $k . '": ';
40 $r .= is_array($v) ? $this->getSerializedArray($v, $ind . ' ') : '"' . str_replace($from, $to, $v) . '"';
42 return $is_flat ? $ind . '[' . $n . $r . $n . $ind . ']' : $ind . '{' . $n . $r . $n . $ind . '}';
47 function isAssociativeArray($v) {
48 foreach (array_keys($v) as $k => $val) {
49 if ($k !== $val) return 1;