我正在进行此API调用,我从他们的API获取Google图书。但是,浏览器中的最终结果是<pre>
标记中的预格式化代码(它也会破坏JSON,并因该标记而引发错误)。我如何才能获得它,以便在浏览器中显示实际网站,而不是原始代码?
public function findAction(Request $request)
{
$form = $this->createFormBuilder(null, ['csrf_protection' => false])
->add('Volume', TextType::class)
->add('Search', SubmitType::class)
->getForm();
$form->submit($request->query->all());
if($form->isSubmitted() && $form->isValid()) {
$client = new Client();
$body = $client->get("https://www.googleapis.com/books/v1/volumes?q=".$form->get('Volume')->getData());
$response = $body->getBody()->getContents();
$response = json_decode($response, true);
if(array_key_exists('items', $response)){
return $this->render('BlogsiteSearchBundle:Page:result.html.twig', ['items' => $response['items']]);
} else {
return new Response('Google did not have any items for this entered data', 400);
}
}
return new Response('Google Volume Not Found', 404);
}