News Feed
Sections




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

Lorna Mitchell's Blog:
PHP and JSON
February 11, 2010 @ 10:55:06

Lorna Mitchell has taken a look at using JSON in PHP applications in a new post to her blog. More specifically, she looks at how to get it working and a downfall or two that comes with it.

This is a quick outline on working with JSON from PHP, which is actually pretty simple to do. This post has some examples on how to do it and what the results should look like. JSON stands for JavaScript Object Notation, and is widely used in many languages (not just JavaScript) for serialisation. It is particularly popular for use in web services.

She gives an example of the translation between a PHP array (of subarrays) out into a JSON message complete with grouping. She does mention one problem that using this data format has, though - the lack of typing information that comes along with the message details. That can mean the difference between an array being pushed in on the sending side and an object (from json_decode) coming out the other side. As noted in the comments, though, there's a second parameter for json_decode that tells it to force the output as an array instead (along with a mention of another helpful constant in PHP 5.3 - JSON_FORCE_OBJECT).

0 comments voice your opinion now!
json example object array webservice


blog comments powered by Disqus

Similar Posts

Jani Hartikainen's Blog: Did you think your site validated input properly? Think again!

Alexey Zakhlestin's Blog: Syck 0.9.2

Stoyan Stefanov's Blog: Fancy Formatting

Patrick Allaert's Blog: Readable PHP code #2 - Make your API handle more!

David Coallier's Blog: PHP Namespaces (Part 1: Basic usage & gotchas)


Community Events

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


series release introduction version security interview extension php7 podcast language laravel5 laravel example framework library community opinion list voicesoftheelephpant api

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