【问题标题】:Accessing Json objects in perl and reuse it in another JSON在 perl 中访问 Json 对象并在另一个 JSON 中重用它
【发布时间】:2017-06-20 05:52:06
【问题描述】:

我在我的 mason 处理程序中收到了如下格式的参数:

$data = {
    'cacheParams' => 0,
    'requests' => {
        'locationId' => 1,
        'uniqueId' => [
            'ABC',
            'DEF',
            'XYZ'
        ]
    }
};

我可以使用$data['requests'] 访问请求。如何访问存储在请求中的值,即 locationId 和 uniqueId ?我需要通过以下方式使用这些值来形成另一个 JSON:

my $input = {
    stateID => 44,
    locationId => requests.locationId,
    uniqueId => requests.uniqueId
    .
    .
    .

}

【问题讨论】:

  • > 我可以使用 $data['requests'] 访问请求。您的意思是 $data{'requests'} 而不是 $data['requests']

标签: json perl mason


【解决方案1】:

$data['requests'] 对象应该是一个哈希值。因此,您可以访问如下所示的密钥:

$data['requests']->{'locationId'}
$data['requests']->{'uniqueId'}

or 

$requests = $data['requests']
$locationId = $requests->{'locationId'}
$uniqueId = $requests->{'uniqueId'}

【讨论】:

    猜你喜欢
    • 2012-08-29
    • 2016-08-10
    • 2012-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    • 2021-09-19
    • 1970-01-01
    相关资源
    最近更新 更多