News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint PHP Blog:
How to Use the JsonSerializable Interface
May 05, 2014 @ 11:50:28

Matrin Hardy has a new tutorial posted to the SitePoint PHP blog today showing you how to use the JsonSerializable interface to work with objects and converting them to JSON.

Over the past few years JSON has taken over as the king of data interchange formats. Before JSON, XML ruled the roost. It was great at modeling complex data but it is difficult to parse and is very verbose. [...] I think we could all agree that writing less code that in turn requires less maintenance and introduces less bugs is a goal we would all like to achieve. In this post, I'd like to introduce you to a little known interface that was introduced in PHP 5.4.0 called JsonSerializable.

He splits the rest of the post out into three different parts: the "ugly" method of converting a sample Customer object into a JSON string (through an array), the "bad" method using a "toJson" method and finally the "good", implementing a class that implements the JsonSerializable interface for easy JSON-ification.

0 comments voice your opinion now!
jsonserializable interface tutorial introduction beginner

Link: http://www.sitepoint.com/use-jsonserializable-interface/

blog comments powered by Disqus

Similar Posts

SitePoint.com: Create Dynamic Images with ImageMagick

Web Developer Juice: 11 easy steps for installing Apache ActiveMQ and configuring it for PHP applica

PHPBuilder.com: Introduction to Arrays and Hashes in PHP - The ABC's of PHP Part 7

DevShed: Introducing the Facade Pattern in PHP 5

Chris Jones: Getting Started with PHP Zend Framework 2 for Oracle DB


Community Events





Don't see your event here?
Let us know!


community list symfony framework library language release interview introduction conference opinion artisanfiles tool podcast series voicesoftheelephpant version composer security laravel

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework