JSON and PHP: More Than Web Services
|
|
|
Click to rate: |
|
|
|
444 votes / avg. rating 6.46%
|
|
In the midst of all the wonderful AJAX libraries in the wild, many today still don't understand the underlying technologies of AJAX that make it so powerful. In this article php|architect's publisher Marco Tabini covers JSON, the magic format that makes serializing data between Javascript and other languages (often server-side) a breeze. Simplicity, velocity and power are the gifts of JSON.
Ah, complexity: the mother of all consulting fees! For developers who cut their teeth on the computers of yesteryear, some aspects of today's programming world are quite puzzling. If you remember a time when 48kB of RAM could only be acquired in exchange for several months' worth of savings, the fact that your average empty Microsoft Word document wouldn't fit in the entire amount of memory once available to your entire computer (including operating system and programming language) is very disturbing. Ditto if your first hard disk weighed ten pounds and required about thirty seconds to whirr up to speed. To people like these, the evolution of the lowly text file into today's uber-complex monsters just sounds wrong. We have somehow managed to delude ourselves that the Internet's pervasion of every sort of market and application requires that every single communication take place using technologies designed to handle everything from ice cream flavours to the plans for a nuclear power plant. Witness the explosion of the XML phenomenon, and its monstrous children, like XML-RPC and SOAP are complex enough to require automated tools for generating the code required to generate the requests and responses required to run a web service. Try saying that three times in a row! A Simpler, Gentler ProtocolThe truth is that XML and XML-based web service protocols, while useful in the right scenarios, are overkill for most applications. You probably don't need an iron-clad error reporting mechanism and super-strict data typing if all you're trying to do is pull a list of pictures from your favourite photo storage service so that you can show them on your web page. On the other hand, having to parse XML with Javascript—a language whose browser support is about as consistent as HTML's—is loads of fun and fully justifies the hell you have to go through to get SOAP working server-side... not.
In the past year or so, a lot of support has been building up for JSON, which stands for JavaScript Object Notation. JSON is a format indigenous to Javascript that makes it possible to encapsulate arbitrary data in an object wrapper and serialize it to plain—just like php's serialize() function, or XML. There are two main differences between JSON and the other serialization techniques that make it uniquely suited to web service data interaction: - Javascript understands JSON natively, which means that you won't have to do any parsing on the client side
- JSON is very compact and extremely simple, which makes it ideal for complex AJAX interfaces and busy websites where bandwidth and server-side processing power comes at a premium. Its simplicity also makes implementing a JSON parser very simpler in practically every language
On the flip side, JSON does not offer the level of consistency and accuracy that XML can provide, nor does it offer many of the advanced characteristics of SOAP, such as a well-defined error-reporting mechanism or proper data typing.Think of JSON as a scooter, and SOAP as an armoured vehicle. Your bank probably won't trust its money to the former, but you don't need the latter if you're pulling search results from Yahoo!
 |
|
 |
|
Tags:
php, json
Tags Help
Tags are keywords associated with a web page that help classifying information. You can find a good explanation here.
To add one or more tags to this page, simply enter them below (separate them with a comma) and hit enter or click on the "Go" button.
|
|
 |
|
 |
|