|
網誌存檔
熱門網志
|
|
|
Understanding JSON: the 3 minute lesson What does it stand for?JavaScript Object Notation.[A ridiculous name. It should be called Lightweight Ecmascript Object Notation, or `LEON` for short. ;-)] And what does that mean?JSON is a syntax for passing around objects that contain name/value pairs, arrays and other objects. Here`s a tiny scrap of JSON: {"skillz": {"web":[{"name": "html", "years": "5"},{"name": "css", "years": "3"}]"database":[{"name": "sql", "years": "7"}]}}You got that? So you`d recognise some JSON if you saw it now? Basically: Squiggles, Squares, Colons and Commas
Think `XML with Anorexia`(Or if you`re as old as me, think "`.INI` files, with hierarchy.") JSON is like XML because:
JSON is UNlike XML because:
But Why? What`s good about it?When you`re writing ajax stuff, if you use JSON, then you avoid hand-writing xml. This is quicker. Again, when you`re writing ajax stuff, which looks easier? the XML approach or the JSON approach: The XML approach:
versusThe JSON approach:
So this is Object-Oriented huh?Nah, not strictly. JSON is about as object oriented as VB6. It provides a nice encapsulation technique, that you can use for separating values and functions out, but it doesn`t provide anything inheritence, polymorphism, interfaces, or OO goodness like that. It is certainly a step in the right direction though, making javascript easier to maintain, share and reuse. Thomas Frank wrote a nifty little javascript library called classyJSON for adding inheritance and scoping capabilities to JSON code. And it`s just for the client-side right?Yes and no. On the server-side you can easily serialize/deserialize your objects to/from JSON. For Three minutes is nearly up....As near as a I can tell, JSON was invented by a guy called Douglas Crockford. Read his website if you want, he`s pretty funny. Now Go And Read Someone Who Knows(Retrieved from Delicious using JSON!)
That`s all.I`ve only tinkered with this stuff for a few minutes -- so I`ve probably said some completely wrong things. If so, please leave a comment, telling me what an idiot i am. I`ll be happy to correct any specific mistakes. Best of luck! (Side Note:If you replace { and } with "<" and "/>", and you replace ":" with "/"... you`d have something very similar to gaXml. Funny old world. (Other side note: Jason and Ajax were both mythical greek heroes. Prediction: other forthcoming technology jargon will include: Heracles, Perseus, Deucalion, Theseus and Bellerophon.) |
-------------------------------------------------
| 上一篇:Delphi for PHP | 下一篇:Mastering JSON ( JavaScript Object Notation ) |


