Understanding Json:3 Minute Courses _json

Source: Internet
Author: User
Tags eval json script tag web services
    1. You never heard of json two months ago.
    2. You heard the word one months ago, but you didn't notice.
    3. A week ago you found out that the word was mentioned many times and started thinking, yes ... There's some junk stuff to learn.
    4. Today you are awakened by a ringing in the depths of your mind, wondering: What the hell is this json thing? Why all of a sudden it's everywhere!

So I went home in the evening on a slow bus (usually very slowly in Friday), and I got myself a lot of information about JSON. So I can gently take you into the front of the JSON.

This is the beginning ...

What do these letters mean?

JAvaScript Object Notation.

[a funny name.] It should be called Lightweight Ecmascript Object Notation, or simply ' LEON '. ]

What kind of thing is it?

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

Here is a small section of the JSON code:

{"Skillz": {"
	Web": [
		{"name": "HTML",
		 "Years": "5"
		},
		{"name": "CSS",
		 "Years": "3"
		}],
	' database ': [
		{' name ': ' SQL ',
		 ' Years ': ' 7 '}
		]
}}

You know what I'm looking for? So when you see it again, you know it's JSON. Main parts:

Curly bracket, square bracket, colon and comma

    1. The Curly bracket represents a "container"
    2. Square brackets Mount Array
    3. Names and values are separated by colons
    4. Array elements are separated by commas

Think of it as "an anorexic XML."

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

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

JSON is much like XML because:

    1. They all "describe themselves," which means that values are enumerable, "human readable."
    2. There is a hierarchy. (For example, you can store values in a value)
    3. Can be parsed and used by a variety of programming languages.
    4. Can be passed by using AJAX methods (e.g. HttpWebRequest)

JSON is not the same as XML because:

    1. In XML there are 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 simply passed in JavaScript into the eval () method using the
    4. There is an array in JSON {Each element has its own name}
    5. In XML you can use any desired name for an element, and in JSON you can't use reserved words in JavaScript.

But why? What's so good about it?

When you write something like Ajax, if you use JSON, you're going to have to spell XML manually. More rapidly.

Similarly, when you write something like Ajax, what's the easiest? XML method or JSON method:

XML method:

  1. Retrieve an XML file
  2. Loop it, extract the value from it
  3. Processing these values, and so on

Contrast

Json method:

  1. Retrieve the JSON string.
  2. ' Eval ' JSON data

Is it object oriented?

No, strictly speaking, No.

It's like an Object-oriented object in the VB6. It provides a good encapsulation mechanism that you can use to isolate data and methods, but it does not provide any inheritance, multimodal, interface, or other similar object-oriented things

Clearly, it is a step forward in the direction of making JavaScript easier to maintain, analyze, and reuse.

Thomas Frank wrote a smart JavaScript library called Classyjson, which adds features such as inheritance and definition to the JSON code.

Is it just for the client?

Yes, and not. On the server side you can easily serialize objects into JSON or vice versa. It .net may be quicker for programmers to use a class library like Json.NET to automate these operations (I reckon using reflection mechanisms), or you can use your own programs to do these things.

3 minutes near the end ....

As I know, JSON was invented by a guy named Douglas Crockford. If you like, you can look at his website, he is very interesting.

Now go and read what people who know json write.

(plundered 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 completely wrong. If so, please leave a message and tell me how stupid I am. I would be happy to correct any mistake. Good luck!

(Side note: If you replace {and} with "<" and "/>", change ":" to "/" ... You're going to get a lot like gaxml. Interesting world.

(Side note 2:jason and Ajax are the heroes of Greek mythology.) Notice: Other upcoming technical waste includes: Heracles, Perseus, Deucalion, Theseus
and Bellerophon. )

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.