php - 如何分解和重用 curlopt 响应?
问题描述
我一直在努力curlopt
回复很长一段时间,希望大家能给我一些指导。
如果您请访问以下页面:https ://niarthgin.com/api/result.php
这将使用 生成一个简单的响应curlopt
。这是我用来获得这些结果的代码:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.bungie.net/Platform/Destiny2/SearchDestinyPlayer/2/Niarthgin/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"postman-token: xxxx",
"x-api-key: xxxx"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
我想打破这种反应,但我不知道该怎么做。例如,在该响应中,您有MembershipType
一个displayName
等。如何单独解析响应?就像我知道我可以解析响应一样,json.parse()
但这只会解析给定的字符串。我希望能够分段解析响应..
谢谢阅读!:)
解决方案
推荐阅读
- python - 如何从两个列表中进行唯一随机选择
- python - 如果输入数据被规范化,则 ML 模型过拟合
- angular - Angular 8 应用程序开发和生产的不同资产位置
- docker - 如何符号链接多个目录
- sql-server - 禁用 Sql Server 查询日志记录
- node.js - Lambda 函数无法从 dynamo DB for amazon lex 获取数据 - 空响应
- java - Java 类从 Kotlin 中的适配器访问数据
- php - ORDER BY 不在 while() 循环中工作,PHP
- python - 当我使用内联 sql 魔术时,jupyter notebook pyspark sparkmagic 错误
- javascript - Angular MatDialog 事件类型