2012-12-27 37 views

回答

2

Mojolicious具有非常好的JSON编码/解码,而下面的示例是不完全的JSON-RPC,这是小事,使之完全符合:

post '/prefetch' => sub { 
    my ($self) = @_; 

    my $post = $self->req->json; 

    my %row; 
    for my $key (qw(country state city district suburb address number complement latitude longitude)) { 
     $row{$key} = $post->{$key} if exists $post->{$key}; 
    } 
+0

是测试更好的写作'如果定义了$岗位 - > {$键}'? –

+0

谢谢@JoelBerger!看起来像来自旧代码的货物崇拜:P – creaktive