首页 > 解决方案 > StdClass 对象响应作为 PHP 中的变量

问题描述

我收到了来自 API 请求的响应。

object(stdClass)#28 (3) { 
   ["Success"]=> bool(true) 
   ["Message"]=> string(0) "" 
   ["Invoice"]=> object(stdClass)#29 (4) { 
       ["Number"]=> string(6) "2313123" 
       ["Series"]=> string(2) "SM" 
       ["Link"]=> string(22) "https://randomlinkhere" 
       ["LinkPlata"]=> NULL 
   } 
}

为了得到这个回复,我使用:

$context  = stream_context_create($request);
$result = file_get_contents($url, false, $context);

if ($result === FALSE) { /* Handle error */ }

var_dump(json_decode($result));

现在我正在尝试阅读回复。我需要阅读

["Link"]=> string(133) "https://randomlinkhere"

我只需要获取指向变量的链接,例如 $variable = https://randomlinkhere

["Series"]=> string(2) "SM"

我只需要将该系列获取到变量,例如 $variable = SM

我尝试了很多东西,没有任何效果。

我最好的结果是:

$myArray = explode(',', $result);
print_r($myArray[4]); 

Wich 给了我下一个结果:

"Link":"https://randomlinkhere"

标签: phpvariables

解决方案


推荐阅读