Changeset 6126 for trunk/include/ws_protocols/json_encoder.php
- Timestamp:
- May 8, 2010, 9:22:29 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/ws_protocols/json_encoder.php
r5196 r6126 21 21 // | USA. | 22 22 // +-----------------------------------------------------------------------+ 23 24 25 #_____________________ PHP 5.226 if (! function_exists('json_encode')) {27 function json_encode($data) {28 switch (gettype($data)) {29 case 'boolean':30 return ($data ? 'true' : 'false');31 case 'null':32 case 'NULL':33 return 'null';34 case 'integer':35 case 'double':36 return $data;37 case 'string':38 return '"'. str_replace(array("\\",'"',"/","\n","\r","\t"), array("\\\\",'\"',"\\/","\\n","\\r","\\t"), $data) .'"';39 case 'object':40 case 'array':41 if ($data === array()) return '[]'; # empty array42 if (range(0, count($data) - 1) !== array_keys($data) ) { # string keys, unordered, non-incremental keys, .. - whatever, make object43 $out = "\n".'{';44 foreach($data as $key => $value) {45 $out .= json_encode((string) $key) . ':' . json_encode($value) . ',';46 }47 $out = substr($out, 0, -1) . "\n". '}';48 }else{49 # regular array50 $out = "\n".'[' . join("\n".',', array_map('json_encode', $data)) ."\n".']';51 }52 return $out;53 }54 }55 }56 23 57 24 class PwgJsonEncoder extends PwgResponseEncoder
Note: See TracChangeset
for help on using the changeset viewer.