Understand JSON: 3-minute course _ json

Source: Internet
Author: User
If you are the same as me (I am afraid you are), so far, this should be your experience in JSON
  1. Two months ago, youNeverI have heard of JSON
  2. You heard this word a month ago but didn't pay attention to it.
  3. A week ago, you found that this word was mentioned many times and started to think,That's right... There are some junk things to learn.
  4. Today, you are awakened by an alarm in your heart, thinking:What is this damn json? Why is it suddenly everywhere!

So in the evening I took a slow bus back home (usually very slow on Friday) and found myself a lot of JSON information. So I can bring you to the JSON gate elegantly.

This starts...

What do these letters mean?

JAvaSBytesOBjectNOtation.

[A funny name. It should be calledLIghtweightECmascriptOBjectNOtation, or 'leon' for short '. ]

What is it?

JSON is a syntax for passing objects. objects can be name/value pairs, arrays, and other objects.

The following is a small JSON code:

{"skillz": {"web":[{"name": "html", "years": "5"},{"name": "css", "years": "3"}],"database":[{"name": "sql", "years": "7"}]}}

Do you understand it? When you see it again, you will know that it is in JSON format. Main Parts:

Square arc, colon, and comma
  1. The arc represents a "container"
  2. Array loaded with square brackets
  3. Names and values are separated by colons.
  4. Array elements are separated by commas
Think of it as "XML with anorexia"

(If you are as old as me, you can think of it as a hierarchical '. INI' file)

(If you are a self-righteous Lisp clown, you can think of it as "S-expressions)

JSON is similar to XML, because:
  1. They all "self-describe", which means that the values are enumerated and "human readable ".
  2. All are hierarchical. (For example, you can store values in values)
  3. It can be parsed and used by multiple programming languages.
  4. Can be passed using AJAX (for example, httpWebRequest)
JSON is different from XML because:
  1. XML contains angle brackets and standard signatures at the beginning and end of the element: JSON uses curly brackets and is only used at the beginning and end of the data.
  2. JSON is more concise and undoubtedly more suitable for human writing. It may also make us read it more quickly.
  3. JSON can be passed to the eval () method in JavaScript.
  4. JSON contains arrays {each element does not have its own name}
  5. In XML, you can use any desired name for an element. In JSON, you cannot use reserved words in Javascript.
But why? What's better about it?

When you write ajax and other things, if you use JSON, you are encouraged to manually spell XML. Faster.

Similarly, when you write something like ajax, how is it the easiest? XML or JSON:

XML method:
  1. Retrieve an XML file
  2. Loop it to extract values from it
  3. Process these values, etc.
JSON comparison method:
  1. Retrieves a JSON string.
  2. 'Eval' JSON data
Is it object-oriented?

No. Strictly speaking, No.

It is like the object-oriented method in 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.

Obviously, it makes javascript easier to maintain and makes analysis and reuse a step forward.

Thomas Frank wrote a clever javascript library calledClassyJSONIt adds features such as inheritance and definition range to the JSON code.

Is it used only on the client?

Yes, no. On the server side, you can easily serialize an object to JSON or vice versa. For.net, Programmers can use class libraries like Json.net to automate these operations (I guess they use reflection mechanisms), or you can use your own programs to do these things faster.

It will end in 3 minutes ....

As far as I know, JSON was invented by a guy named Douglas Crockford. If you like, you can check out his website, which is very interesting.

Now, read what is written by someone who understands JSON.

(Searched from Delicious using JSON !)

  • DOM Query Speed Test
  • 24 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
This is all.

I can only sort out these things in a few minutes-everything I said may be totally wrong. If so, leave a message to tell me how silly I am. I will be happy to correct any mistake. Good luck!

(Edge Note: If you replace {And} with "<" and "/>", replace ":" with "/"… You will get something very similar to gaXml. Interesting world.

(Side Note 2: Jason and Ajax are both heroes in Greek mythology. Notice: other upcoming technical spam include Heracles, Perseus, Deucalion, And Theseus.
And Bellerophon .)

Related Article

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.