Josh Randall Josh Randall -5 years ago 283
JSON Question

Cakephp read and write json files.

I am new to cakephp. I am trying to save json output as a file in webroot. I would also like read the file into a array.

I know we could output array as json object using json_encode($array). But I am stuck creating and reading json files into an array.

I appreciate any help.

Answer Source
$json = '{"key":"value"}';
$file = new File('/path/to/file', true);
$file = new File('/path/to/file');
$json = $file->read(true, 'r');
$json2array = json_decode($json);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download