Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.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
Php Can';无法从webservice返回的代码中获取值_Php_Arrays_Json - Fatal编程技术网

Php Can';无法从webservice返回的代码中获取值

Php Can';无法从webservice返回的代码中获取值,php,arrays,json,Php,Arrays,Json,当我使用系统的RESTAPI时,我无法将特定“字段”的值返回到PHP中。 错误消息显示: 注意:尝试在中获取非对象的属性 是我得到回报的一部分。现在我想将例如“Owner”存储到一个php变量中 但是使用$response->Owner或$response->Ticket->Owner 我得到了非对象错误的属性看看这个: $obj = '{"Ticket":[{"Owner":"root@localhost","EscalationTime":0,"Age":17628,"ChangeBy":7

当我使用系统的RESTAPI时,我无法将特定“字段”的值返回到PHP中。 错误消息显示:

注意:尝试在中获取非对象的属性

是我得到回报的一部分。现在我想将例如“Owner”存储到一个php变量中

但是使用
$response->Owner
$response->Ticket->Owner

我得到了非对象错误的属性

看看这个:

$obj = '{"Ticket":[{"Owner":"root@localhost","EscalationTime":0,"Age":17628,"ChangeBy":7}]}';  
// This is what you get from your rest API

$arr = json_decode($obj);  // decode the JSON string

print_r($arr);
输出将为:

stdClass Object
(
    [Ticket] => Array
        (
            [0] => stdClass Object
                (
                    [Owner] => root@localhost
                    [EscalationTime] => 0
                    [Age] => 17628
                    [ChangeBy] => 7
                )

        )

)
因此,您可以访问以下数据:

echo $arr->Ticket[0]->Owner;
输出将是: root@localhost


解码后,请使用以下命令:

echo $response["Ticket"][0]['Owner'];

你试过先解码这个JSON字符串吗?当我解码时,打印结果如下:数组([Ticket]=>Array([0]=>Array([ArchiveFlag]=>n[EscalationTime]=>0[Age]=>19087[TicketID]=>3[UnlockTimeout]=>1565776558[Changed]=>2019-08-1409:55:58[LockID]=>1[CustomerID]=>1[ResponsibleID]=>1[EscalationResponseTime]=>0[RealTillTimeNotUsed]=>0[OwnerID]=>1[PriorityID]=>3[QueueID]=>2[Owner]=>root@localhostThen您必须以数组而不是对象的形式访问它
echo $arr->Ticket[0]->Owner;
echo $response["Ticket"][0]['Owner'];