Make Zend_Rest_Server return JSON instead of XML using ZF
Can Zend_Rest_Server return Json ? If not, what are the al开发者_运维百科ternatives ( other lib suggestions are ok also)
Zend_Rest_Server outputs XML, eventhough not clearly specified in the documentation.
There are some alternatives:
You could leverage the whole MVC architecture given by Zend Framework, thanks to Zend_Rest_Route
and Zend_Rest_Controller
.
You will find a complete example here:
http://techchorus.net/create-restful-applications-using-zend-framework
Again, the example displays plain string, but using json_encode
, or Zend_Json::encode
should return json.
And finally, a complete (advanced) example that use the ContextSwitch
feature:
http://www.chrisdanielson.com/2009/09/02/creating-a-php-rest-api-using-the-zend-framework/
(If you need more information on ContextSwitch
Action Helper, please refer to the documentation.)
Unfortunately, my limited reputation prevent me from giving you more links, but Google is your friend using some magic words such as zend rest json
or zend controller rest json
...
精彩评论