php - 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"
解决方案
推荐阅读
- batch-file - 如何获得使用批处理文件复制大文件(2.2 GB)的实时进度条?
- java - kafka 消费者尝试连接到随机主机名而不是正确的一个
- python - 从子流程输出中获取价值
- php - 如何在sql中获取两个给定日期之间的日期
- ruby-on-rails - 为什么捆绑器在寻找 mysql2 -v '0.4.4' --source 'https://rubygems.org/'
- java - java中的泛型方法来总结给定列表中的所有值,无论它是String,int,double
- r - r - 按数据框中的数值过滤字母数字因子列
- spring - Spring MVC 中最好的 HandlerMapping 是什么?
- jquery - fancybox V3 + isotope 排序依据
- vba - 将多个文本框值传输到数组