google api的响应是这样的
{
"kind": "books#volumes",
"totalItems": 1956,
"items": [
{
"kind": "books#volume",
"id": "P_zMW3EHnTEC",
"etag": "BWKRqUEh9VU",
"selfLink": "https://content.googleapis.com/books/v1/volumes/P_zMW3EHnTEC",
"volumeInfo": {
"title": "The 48 Laws Of Power",
"authors":
现在主数组是 $bookBatch 并且其中的项目是一个数组。items 数组包含 volumeInfo 数组。在该 volumeInfo 中有标题。我想得到title。所以我写了以下foreach循环
foreach($bookBatch['items'] as $row)
{
foreach($row['volumeInfo'] as $volumeinfo)
{
echo $volumeinfo['title'];
}
}
但我得到这样的输出
TP2TB0ehhhTS2YBpehhhTP2TB0ehhhTAN2TB0ehhhPIT1IB0ehhhP2SB0ehhhPP1TBpehhhPW1SBpehhhSTP2HB0ehhhPAP2IB0ehhh
相反,我应该得到像 The 48 Laws of Power 这样的标题
编辑 1
$query="power";
$url = "https://www.googleapis.com/books/v1/volumes?q=".$query;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$bookBatch = curl_exec($ch);
curl_close($ch);
$bookBatch = json_decode($bookBatch, true);