Perl 如何解析数据哈希格式的SOAP响应输出?有关详细信息,请参见下面的代码

Perl 如何解析数据哈希格式的SOAP响应输出?有关详细信息,请参见下面的代码,perl,parsing,soap,hash,Perl,Parsing,Soap,Hash,正在打印上述代码: 散列(0x47f8b28) 在上一个print语句中,如果我使用dumper,我将得到以下响应。 打印转储程序($answer) 如何解析所需的值,如, 我需要能够轻松访问“connectionId”和“1557666855346” 欢迎提出任何意见。提前谢谢。 谢谢 Kaushik KM.$answer似乎是一个散列引用,因此您可以使用正常的解引用技术访问数据: $VAR1 = { 'outargs' => {

正在打印上述代码: 散列(0x47f8b28)

在上一个print语句中,如果我使用dumper,我将得到以下响应。
打印转储程序($answer)

如何解析所需的值,如, 我需要能够轻松访问“connectionId”和“1557666855346”

欢迎提出任何意见。提前谢谢。 谢谢
Kaushik KM.

$answer
似乎是一个散列引用,因此您可以使用正常的解引用技术访问数据:

$VAR1 = {
          'outargs' => {
                         'connectionId' => '1557666855346'
                       }
        };
输出:

my $conn_id = $answer->{outargs}{connectionId};
print "$conn_id\n";
不工作,正在抛出错误,如下所示: 现在在CreateEvent.pl第64行禁止标量上的实验键。 在创建时,键的arg 1的类型必须是散列或数组(不是键/值散列切片) Event.pl第64行,靠近“}

有人能纠正这个问题吗。

在answear={outargs=>{key1,key2}中循环所有键 输出:

# This should remove the error of "Experimental keys on scalar is now forbidden" by wrapping the hashRef in %{}
for ( keys %{$answear->{outargs}}) {
    # $_ here will be the key and if you want to access the value use $answear->{outargs}->{$_}
    print "key: $_, value: $answear->{outargs}->{$_}\n";
}

我希望这会对您有所帮助!

完美。但我如何访问密钥?如果我不知道响应中的所有密钥是什么,该怎么办?我想动态打印所有密钥及其值。请帮助,@ikegami您能帮我编写代码吗?我希望您理解我的问题,在上面的响应中…我可能会得到10个k还有
ConnectionID
及其值…还有
outargs
我们可能也会得到多个散列。因此我希望能够访问每个散列并打印它们。请帮助循环。这应该作为一个新问题提交。
%${$answer}{$key}
语法不正确。
1557666855346
my %fhash = %{$answer};
my $key = "";
foreach $key (keys %fhash)
{
print "keys are\n \"$key\" its value is (${$answer}{$key}) \n";

    foreach my $key2 (keys %${$answer}{$key})
    {
    print "keys of(${$answer}{$key})\n \"$key2\"\n";
    }
}
# This should remove the error of "Experimental keys on scalar is now forbidden" by wrapping the hashRef in %{}
for ( keys %{$answear->{outargs}}) {
    # $_ here will be the key and if you want to access the value use $answear->{outargs}->{$_}
    print "key: $_, value: $answear->{outargs}->{$_}\n";
}
key: connectionId, value: 1557666855346