tags:

views:

1013

answers:

3

I've created a simple REST service that serves data as XML. I've managed to enable XML, JS and RSS format but I can not find the way to enable JSON format. Is JS == JSON? Guess not :).

How can I enable this in version 1.2/1.3?

Thx!!

+2  A: 

If you have PHP 5.2 or higher, it ships with JSON encode/decode support. Check the docs here.

You'll probably need to do the encoding/output by hand, but it should be trivial to code.

Bonus points would be to build it as a behavior :)

Edit:

Check out the $javascript->object() method here, it may do what you want.

inkedmn
I'm talking about CakePHP framework and the aoutomatization (.xml, .js, .rss... .json? ).
xpepermint
A: 

Quick google search indicates that there are is a json Component for CakePHP. Link to article discussing its use in Cake 1.2: http://www.pagebakers.nl/2007/06/05/using-json-in-cakephp-12/

Travis Leleu
A: 

Router::parseExtensions('json');

neilcrookes