Syntaxerror Error: JSON.parse: Unexpected Character at line 1 column 1 of the JSON data

Asked

Viewed 509 times

0

I am trying to create an api in my application, but it is returning me the following error: Syntaxerror: JSON.parse: Unexpected Character at line 1 column 1 of the JSON data

I’m using Zend Framework 3.

<?php header('Content-type: application/json; charset=utf-8');
echo json_encode(array("teste"=>"123"), JSON_UNESCAPED_UNICODE);

Is any configuration of Zend giving conflict?

1 answer

-1

try like this:

use Zend\Json\Json;
$data = array("teste"=>"123");
echo Json::encode($data);

or if using Zend-Diactoros

$data = array("teste"=>"123"); return new JsonResponse($data,200);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.