Understanding Json:3 Minute Courses
Blog Category:
Jsonajaxjavascriptxmllisp
This article is from Understanding json:the 3 Minute Lesson this article translated.
If you're like me (I'm worried about you), so far, this should be your experience with JSON:
- Two months ago, you never heard of JSON.
- One months ago, you heard the word, but you didn't notice.
- A week ago you found that the word was mentioned many times and began to think, yes ... There's a lot of junk to learn.
- Today, you are awakened by an alarm in the depths of your heart, thinking: What is this damn json? Why all of a sudden it's everywhere!
So in the evening I rode a slowly bus back home (Friday is usually very slow), and then I found myself a lot of JSON data. So I can gently take you into the gates of JSON.
This is the beginning ...
What do these letters mean?
J AvaS cript O bject N otation.
[a funny name.] It should be called L ightweight E cmascript O bject N otation, or simply ' LEON '. ]
What is it, a thing?
JSON is a syntax for passing objects, which can be name/value pairs, arrays, and other objects.
Here is a small snippet of JSON code:
{"Skillz": {"Web": [{"name": "HTML", "Years": "5"},{"name": "CSS", "Years": "3"}], "database": [{"Name": "SQL", "Years": "7 "}]}}
You understand me? So when you see it again, you know it's JSON. Main parts:
Curly brackets, square brackets, colons, and commas
- Curly brackets denote a "container"
- square brackets to load an array
- Names and values are separated by colons
- Array elements are separated by commas
Think of it as "anorexic XML."
(If you're as old as I am, you can think of it as a hierarchical relationship.) INI ' file)
(If you're a self-righteous Lisp clown, think of it as "s-expressions" and be smug)
JSON is much like XML, because:
- They are all "self-describing", which means that values are enumerated and "human readable"
- are of a hierarchy. (For example, you can store values in values)
- Can be parsed and used in a variety of programming languages
- Can be passed using AJAX methods (e.g. HttpWebRequest)
JSON is not the same as XML because:
- The XML has angle brackets and tag names at the beginning and end of the element: JSON uses curly braces, and is used only at the beginning and end of the data.
- JSON is more concise, no doubt more suitable for human writing, perhaps also allows us to read more quickly.
- JSON can be easily passed to the eval () method in JavaScript.
- There are arrays in JSON {Each element does not have its own name}
- In XML you can use any desired name for an element, and in JSON you can't use a reserved word in JavaScript
But why? What's so good about it?
When you write Ajax or something like that, if you use JSON, you go through the manual spelling of the XML. More quickly.
Also, what's the simplest thing to do when you're writing Ajax? The XML way is still JSON:
XML mode:
- Retrieving an XML file
- Loop it, extract the value from it
- Handle these values, etc.
Compare JSON mode:
- Retrieves the JSON string.
- ' Eval ' JSON data
Is it object-oriented?
No, strictly speaking, No.
It's like an object-oriented VB6. It provides a good encapsulation mechanism, you can use it to separate data and methods, but it does not provide any inheritance, multi-type, interface, or other similar object-oriented things
It is clear that it is a step forward in the direction of making JavaScript easier to maintain, analyze, and reuse.
Thomas Frank wrote a handy JavaScript library called Classyjson , which adds features such as inheritance and definition scope to the JSON code.
Is it just used on the client?
Yes, it's not. On the server side you can easily serialize objects into JSON or vice versa. For .net
, programmers can use a class library like Json.NET to automate these operations (I would expect to use a reflection mechanism), or you can use your own program to do these things sooner.
3 minutes near the end ....
As I know, JSON was invented by a guy called Douglas Crockford . If you like, you can look at his website , he is very interesting.
Now, read what the JSON guy wrote.
(from delicious using JSON !) )
- DOM Query Speed Test
- Ways:don ' t be eval ()
- Understanding json:the 3 Minute Lesson
- Serializing Objects as JavaScript using Atlas, Json.NET and Ajaxpro
- Json–wikipedia, the free encyclopedia
- Introduction to JSON
- XML.com:JSON and the Dynamic Script tag:easy, xml-less Web Services for JavaScript
- Classy JSON
- Ajax JSON Tutoral
- XML to Json–a Converter
That's all.
I can only sort out these things in a few minutes--all the things I say may be totally wrong. If so, please leave a message and tell me how foolish I am. I would be happy to correct any one mistake. Good luck!
(Side note: If you replace {and} with "<" and "/>", change ":" to "/" ... You'll get something very much like a gaxml . Interesting world.
(Side note 2:jason and Ajax are the heroes of Greek mythology.) Trailer: Other upcoming technical waste includes: Heracles, Perseus, Deucalion, Theseus and Bellerophon. )
Original address of this article: Understanding Json:3 Minute Course
Understanding Json:3 Minute Courses