【发布时间】:2019-03-21 01:10:45
【问题描述】:
需要过滤我的 curl json 请求。 我的问题是.. 我的输出列表总是完整的 JSON 列表(链接 1-3)。 我只需要请求链接 1 和链接 3。
请检查我的过滤器示例
$responseData = apiRequest("link/list", array('id' => json_encode(array('1001', '1003'))));
这个过滤器对我不起作用。我该如何解决我的问题? 我很高兴每一个提示
非常感谢
API 请求:
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"
}
]
}
【问题讨论】: