diff --git a/library/think/Model.php b/library/think/Model.php index f4f77c13..5962e636 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -169,6 +169,17 @@ abstract class Model implements \JsonSerializable, \ArrayAccess return !empty($item) ? $item : []; } + /** + * 转换当前模型对象为JSON字符串 + * @access public + * @param integer $options json参数 + * @return string + */ + public function toJson($options = JSON_UNESCAPED_UNICODE) + { + return json_encode($this->toArray(), $options); + } + /** * 获取当前模型对象的主键 * @access public @@ -980,7 +991,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess public function __toString() { - return json_encode($this->toArray()); + return $this->toJson(); } // JsonSerializable