- You never heard of json two months ago.
- You heard the word one months ago, but you didn't notice.
- A week ago you found out that the word was mentioned many times and started thinking, yes ... There's some junk stuff to learn.
- 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
- The Curly bracket represents a "container"
- Square brackets Mount Array
- Names and values are separated by colons
- 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:
- They all "describe themselves," which means that values are enumerable, "human readable."
- There is a hierarchy. (For example, you can store values in a value)
- Can be parsed and used by a variety of programming languages.
- Can be passed by using AJAX methods (e.g. HttpWebRequest)
JSON is not the same as XML because:
- 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.
- JSON is more concise, no doubt more suitable for human writing, perhaps also allows us to read more quickly.
- JSON can be simply passed in JavaScript into the eval () method using the
- There is an array in JSON {Each element has its own name}
- 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:
- Retrieve an XML file
- Loop it, extract the value from it
- Processing these values, and so on
Contrast
Json method:
- Retrieve the JSON string.
- ' 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. )