Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何获取perl json访问哈希引用_Json_Perl - Fatal编程技术网

如何获取perl json访问哈希引用

如何获取perl json访问哈希引用,json,perl,Json,Perl,我正在尝试获取远程主机值,即remotehost。我解码了json,能够得到$name和$id值。但是 访问“remote->host”值(即remotehost)时将数组强制为哈希时索引错误 这个位是一个对象数组(Perl中的哈希)。你不能强迫它。您需要访问第一个元素 # A # | B # | | C # | | | $obj{'remote'}->[0]->{'host'} 注意这

我正在尝试获取远程主机值,即remotehost。我解码了json,能够得到$name和$id值。但是

访问“remote->host”值(即remotehost)时将数组强制为哈希时索引错误

这个位是一个对象数组(Perl中的哈希)。你不能强迫它。您需要访问第一个元素

#   A
#   |           B    
#   |           |    C
#   |           |    |
$obj{'remote'}->[0]->{'host'}
注意这里没有
auth
,因为它与
remote
(标记为A)处于同一级别


试试
$obj{'remote'}{'host'}
你好,谢谢你的回复。我试过了。我收到“将数组强制为哈希值时索引错误”错误。请尝试
$obj{'remote'}[0]{'host'}
 "remote": [
        {
            "host": "remotehost",
            "name": "remotetest"
        }
    ]
#   A
#   |           B    
#   |           |    C
#   |           |    |
$obj{'remote'}->[0]->{'host'}
 {
    "auth" : {
        "req": "1234",
        "link": "http://localhost" 
    },
    "host" : "localhost",
    "name" : "mytest",

    // A
    "remote" : [ // B

        { // C
            "host": "remotehost",
            "name": "remotetest"
        }
    ]
 }