What exactly is JSON?

Source: Internet
Author: User

JSON is relatively simple, the foundation is the most important, this article is to take you to learn JSON Basics the. If you're like me (I'm worried about you), so far, the following 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 mind, 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?

s o n

[a funny name. It should be called    ightweight  e o n

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. name and value separated by colons

4. array elements 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. there are levels. (For example, you can store values in values)

3. can be interpreted and used by a variety of programming languages

4. can be passed 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 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. Process These values, etc.

Compare JSON mode:

1. Retrieve 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 Smart JavaScript Library , called Classyjson , it 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 programs to do these things sooner.

3 minutes near the end ....

Article from: Geek Headlines

What exactly is JSON?

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.