Understanding Json:3 Minute Courses

Source: Internet
Author: User

Understanding Json:3 Minute Courses Blog Category: 
    • Java synthesis
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:

    1. Two months ago, you never heard of JSON.
    2. One months ago, you heard the word, but you didn't notice.
    3. 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.
    4. 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
    1. Curly brackets denote a "container"
    2. square brackets to load an array
    3. Names and values are separated by colons
    4. 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:
    1. They are all "self-describing", which means that values are enumerated and "human readable"
    2. are of a hierarchy. (For example, you can store values in values)
    3. Can be parsed and used in a variety of programming languages
    4. Can be passed using AJAX methods (e.g. HttpWebRequest)
JSON is not the same as XML because:
    1. 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.
    2. JSON is more concise, no doubt more suitable for human writing, perhaps also allows us to read more quickly.
    3. JSON can be easily passed to the eval () method in JavaScript.
    4. There are arrays in JSON {Each element does not have its own name}
    5. 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:
    1. Retrieving an XML file
    2. Loop it, extract the value from it
    3. Handle these values, etc.
Compare JSON mode:
    1. Retrieves the JSON string.
    2. ' 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.