Commits

Harro Verton committed 19178ce

fixed double encoding issue when using all_to_json.php()

Comments (0)

Files changed (1)

application/datamapper/json.php

 	 * @param	DataMapper $object The DataMapper Object to convert
 	 * @param	array $fields Array of fields to include.  If empty, includes all database columns.
 	 * @param	boolean $pretty_print Format the JSON code for legibility.
+	 * @param	boolean		$no_encode		Internal use only. if true, return the result without encoding
 	 * @return	string A JSON formatted String, or FALSE if an error occurs.
 	 */
-	public function to_json($object, $fields = '', $pretty_print = FALSE)
+	public function to_json($object, $fields = '', $pretty_print = FALSE, $no_encode = FALSE)
 	{
 		if(empty($fields))
 		{
 				$result[$f] = $object->{$f};
 			}
 		}
+
+		if ($no_encode)
+		{
+			return $result;
+		}
+
 		$json = json_encode($result);
+
 		if($json === FALSE)
 		{
 			return FALSE;
 		}
+
 		if($pretty_print)
 		{
 			$json = $this->_json_format($json);
 		}
+
 		return $json;
 	}
 
 		$result = array();
 		foreach($object as $o)
 		{
-			$result[] = $o->to_json($fields);
+			$result[] = $o->to_json($fields, FALSE, TRUE);
 		}
 		$json = json_encode($result);
 		if($json === FALSE)