dsilhx5830 2011-06-17 16:30
浏览 63
已采纳

用json_encode()获取一个空字符串

See attached code. for some reason the json_encode() is returning an empty string.
I call it by using $jv = Video::ConvertToJson($video);
Using breakpoints I verified that $video wasn't null, etc.
(using PHP 5.3)
Any ideas?
thx

class Video
{
    private $ID;
    private $Title;
    private $ViewCount;
    private $Description;
    private $IsEmbeddable;
    private $IsPrivate;

    function __construct($id = 0, $title = '', $viewcount=0, $description='', $isembeddable=1, $isprivate=0){
        $this->ID = $id;
        $this->Title = $title;
        $this->ViewCount = $viewcount;
        $this->Description = $description;
        $this->IsEmbeddable = $isembeddable;
        $this->IsPrivate = $isprivate;
    }
    /**
     *
     * Converts a Tfyoutubevideo into a json object
     * @param models\TfYoutubevideos $tfv
     */
     public static function ConvertToJson(models\TfYoutubevideos $tfv){
        $v = new Video();
        $v->ID = $tfv->getId();
        $v->Title = $tfv->getVideotitle();
        $v->ViewCount = $tfv->getVideoviewcount();
        $v->Description = $tfv->getVideoDescription();
        $v->IsEmbeddable = $tfv->getVideoIsEmbeddable();
        $v->IsPrivate = $tfv->getVideoIsPrivate();
        $vj = json_encode($v);
        return $vj;

     }
}
  • 写回答

1条回答 默认 最新

  • drn5375 2011-06-17 16:37
    关注

    json_encode does not serialize private (or protected) member variables. Either copy your object's state into a temporary array or declare member variables as public to mitigate that.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮