需要过滤我的curl json请求。我的问题是..我的输出列表总是完整的JSON列表(链接1-3)。我只需要请求链接1和链接3。
请查看我的过滤器示例
$responseData = apiRequest("link/list", array('id' => json_encode(array('1001', '1003'))));
这个过滤器对我不起作用。我如何解决我的问题?我为每一条提示感到高兴
非常感谢
接口请求:
function apiRequest($command, $requestData = array()) {
$apiKey = "";
$headers = array(
'Authorization: APIKEY '.$apiKey
);
if (!is_array($requestData)) {
$requestData=array();
}
$requestData['apiKey'] = $apiKey;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_URL => 'https://api.example.com/'.$command,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $requestData)
);
if (($responseData = curl_exec($curl))===false) {
curl_close($curl);
/* echo "cURL error: ".curl_error($curl); */
return null;
}
return json_decode($responseData, true);
}
$responseData = apiRequest("link/list", array('id' => json_encode(array('1001', '1003'))));
Json列表:
{
"count": 3,
"links": [
{
"id": 1001,
"name": "Link 1",
"title": "Link Title",
"head": "Links",
"pic": "https://image.com/pic.jpg",
"views": "10,000+",
"country": "US"
}
{
"id": 1002,
"name": "Link 2",
"title": "Link Title 2",
"head": "Links",
"pic": "https://image.com/pic.jpg",
"views": "10,000+",
"country": "US"
}
{
"id": 1003,
"name": "Link 3",
"title": "Link Title 3",
"head": "Links",
"pic": "https://image.com/pic.jpg",
"views": "10,000+",
"country": "US"
}
]
}
发布于 2019-03-21 09:16:50
看起来你想在api :/中做这件事,它甚至提供了这个功能吗?如果是这样,请询问他们,rtm或给我们真正的网站链接,这样我们就可以检查文档。
不过,如果不是这样,那么只需对结果使用array filter即可。
https://stackoverflow.com/questions/55272377
复制相似问题