Permalink
Browse files

fixed bug in json encode

  • Loading branch information...
Mashape
Mashape committed Feb 15, 2011
1 parent 47aaaba commit 971eabf75d9c5d36b4e7492e5adf277115cf8046
Showing with 14 additions and 2 deletions.
  1. +13 −0 mashape/init/json.php
  2. +1 −2 mashape/json/jsonUtils.php
View
@@ -37,4 +37,17 @@ function json_decode($content, $assoc=false) {
}
}
+if (!function_exists('json_encode')) {
+ function json_encode($content, $assoc=false) {
+ require_once(dirname(__FILE__) . "/../json/jsonImpl.php");
+ if ($assoc) {
+ $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
+ }
+ else {
+ $json = new Services_JSON;
+ }
+ return $json->encode($content);
+ }
+}
+
?>
@@ -32,8 +32,7 @@ public static function serializeError($message, $code) {
public static function encodeToJson($text) {
if (is_string($text)) {
- $result = str_replace("\\", "\\\\", $text);
- return '"' . str_replace("\"", "\\\"", $result) . '"';
+ return json_encode($text);
} else if (is_bool($text)) {
if ($text) {
return "true";

0 comments on commit 971eabf

Please sign in to comment.