How to convert Perl objects into JSON and vice versa

前端 未结 4 1533
自闭症患者
自闭症患者 2020-12-10 11:05

I have defined a Point object in a file Point.pm as following:

package Point;
sub new {
    my ($class) = @_;
    my $self = {
        _x =>          


        
4条回答
  •  猫巷女王i
    2020-12-10 11:20

    You need JSYNC.

    use JSYNC;
    use Point;
    my $p = Point->new;
    $p->X(20);
    $p->Y(30);
    
    my $jsync = JSYNC::dump($p, {pretty => 1});
    

    {
       "!" : "!perl/hash:Point",
       "_x" : "20",
       "_y" : "30"
    }
    

提交回复
热议问题