我向 API REST 发出了 GET 请求,并获得了一些数据(base64 编码)。现在我需要从结果中获得一些特定的值,但我不知道如何。这是我到目前为止<?php //BUSCAR DOCUMENTOS $service_url = 'http://192.168.4.77/api/Core.svc/core/PaginatedSearch/P/E/KFRpcG9EVEU6MzMgQU5EIEZjaEVtaXM6WzIwMTktMDYtMjEgVE8gMjAxOS0wNy0zMF0p/0/10'; $ch = curl_init($service_url); curl_setopt($ch, CURLOPT_URL, $service_url); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'AuthKey: top-secret', 'Content-Type: application/json', 'Accept: application/json', )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); $response = curl_exec($ch); $err = curl_error($ch); if ($err) { echo "cURL Error #:" . $err; } else { $datos = json_decode($response,true); foreach ($datos as $k => $v) { $Result = $datos['Result']; $Description = $datos['Description']; $SearchTime = $datos['SearchTime']; $TotalDocuments = $datos['TotalDocuments']; $Data = $datos['Data']; } $test = base64_decode($Data); var_dump($test); } curl_close($ch);?>这就是我得到的,需要获取值(例如:33 2284 21-06-2019 0:00:00)任何帮助将非常感激。
1 回答
冉冉说
TA贡献1877条经验 获得超1个赞
看起来数据是相当结构化的,即使是一团糟。
好像有一个键表示<_DocID>,键,值表示<_Group>,值,然后继续重复。使用它,我们至少可以将其分解为一个更合理的关联数组。
$structured_response = [];
$keys = explode('<_DocID>', $response); //First we'll look for the keys
foreach ($keys as $key) {
if ($key == '') continue;
$data = explode('<_Group>', $key); //Then we'll look for what's around on either side of the value denotation
$key = $data[0]; //Before the key-ending separator will be the key
$value = $data[1]; //After the separator will be the data
$structured_response[$key] = $value; //Now save the data to the array
}
- 1 回答
- 0 关注
- 139 浏览
添加回答
举报
0/150
提交
取消