diff --git a/includes/class.db-api.php b/includes/class.db-api.php index f88d4de..164c331 100644 --- a/includes/class.db-api.php +++ b/includes/class.db-api.php @@ -438,6 +438,30 @@ function error( $error, $code = '500' ) { } + /** + * Converts strings in array to UTF-8 + * Prevents Json from returning nulls values + * with incompatible characters. + **/ + function utf8encoding($inArray) { + + /* our return object */ + $newArray = array(); + + /* step through inArray */ + foreach($inArray as $key => $val) { + if(is_object( $val ) || is_array($val)) { + /* recurse on array elements */ + $newArray[$key] = $this->utf8encoding($val); + } else { + $newArray[$key] = utf8_encode($val); + } + } + + /* return utf8 encoded array */ + return $newArray; + } + /** * Output JSON encoded data. * @todo Support JSONP, with callback filtering. @@ -445,7 +469,7 @@ function error( $error, $code = '500' ) { function render_json( $data, $query ) { header('Content-type: application/json'); - $output = json_encode( $data ); + $output = json_encode( $this->utf8encoding($data) ); // Prepare a JSONP callback. $callback = $this->jsonp_callback_filter( $query['callback'] ); @@ -563,7 +587,7 @@ function object_to_xml( $array, $xml ) { //simple key/value child pair } else { - $xml->addChild( $key, $value ); + $xml->addChild( $key, utf8_encode($value) ); } }