简体   繁体   中英

Remove header of a json file, symfony2

So, i have an array in PHP, and i write to convert this array to a json and then write this json in a file .json :

$fs = new Filesystem();
$fs->dumpFile('test.json', new JsonResponse($this->data));

I'm using filesystem from symfony 2 and JsonResponse to convert array in json.

but with this code, in my file test.json, i have this header :

HTTP/1.0 200 OK
Cache-Control: no-cache
Content-Type:  application/json
Date:          Wed, 11 Dec 2013 18:30:19 GMT

How can i simply remove this header ?

If you just want to save JSON-encoded array into a file, you don't need to use JsonResponse, simple json_encode will suffice.

This may look something like this:

$fs = new Filesystem();
$fs->dumpFile('test.json', json_encode($this->data));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM