mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 15:02:47 +08:00
Model类增加toJson方法输出JSON字符串
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user