我试图转换每个 json_encode($response) 的 ARRAY 但它仍然是一个字符串。我剪断了字符串,所以我得到了它的正确部分,但它只在这个视频中工作,所以我必须使用 $response[position_I_want]。我该如何解决这个问题?感谢大家的帮助!
$response = $YouTubeLink->loader($_GET["ID"]); //my class with the curl function loader
function loader($ID)
{
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://youtube-to-mp32.p.rapidapi.com/api/yt_to_mp3?video_id=$ID", // hier wird die Video ID übergeben
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"x-rapidapi-host: youtube-to-mp32.p.rapidapi.com",
"x-rapidapi-key: a3ab095a57msh2d08de201b482cbp1559dcjsnaa6636261faa"
],
]);
// speichert die api antwort in die Variable response
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
return json_encode($response); // <---This dosent work it gives only string back
}
}
here is the original response
string(377) "{"Status":"Success","Status_Code":404,"Title":"2Pac, Pop Smoke - Write This Down ft. Biggie, DMX, Eazy E, Ice Cube, Dr Dre, NWA, Nipsey, Snoop Dogg","Download_Size":5161074,"Video_Duration":798,"Video_Thumbnail":"https://img.youtube.com/vi/HI6gMkfRjE0/hqdefault.jpg","Full_Video_Link":"https://www.youtube.com/watch?v=HI6gMkfRjE0","Download_url":"<here is the download link>"}"