我的班级实现了
php中的json序列化
然后我的类实现了 jsonSerialize 方法并返回 get_object_vars($this)。
public function JsonSerialize()
{
$vars = get_object_vars($this);
return $vars;
}
Run Code Online (Sandbox Code Playgroud)
问题在于它也返回包括 NULL 变量在内的所有值。我怎样才能只获取非空变量作为 json 输出?