Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand JSON

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to understand JSON". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deep into it slowly to study and learn "how to understand JSON" together.

What do these letters mean?

JavaScript Object Notation.

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

What is it?

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

Here's a little bit of JSON code:

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

Do you understand? Then when you see it again, you know it's JSON. Main parts:

Brackets, square brackets, colons and commas

1. The curly brackets represent a "container."

2. square bracketed load array

3. Name and value separated by colons

4. Array elements separated by commas

Think of it as "XML with anorexia."

(If you're as old as I am, think of it as a hierarchical '.INI' file)

(If you're a self-righteous Lisp clown, think of it as "S-expressions.")

JSON is similar to XML because:

1. They're all "self-describing," which means the values are enumerable, human-readable.

2. Everything is hierarchical. (For example, you can store values in values)

3. can be parsed and used by multiple programming languages.

4. can be passed using AJAX methods (e.g. httpWebRequest)

JSON is different from XML because:

1. XML has angle brackets and tag names at the beginning and end of elements: JSON uses braces and is used only at the beginning and end of data.

2. JSON is more concise, no doubt more suitable for human writing, and perhaps allows us to read faster.

3. JSON can be simply passed to eval() in JavaScript

4. There are arrays in JSON {each element has no name}

5. In XML you can use any name you want for an element; in JSON you cannot 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 eliminating the manual spelling of XML. Faster.

Also, when you write something like Ajax, what's the easiest thing to do? XML or JSON:

XML mode:

1. Retrieves an XML file

2. Loop it, extract values from it

3. Process these values, etc.

contrast

JSON mode:

1. Retrieves the JSON string.

2. 'eval' JSON data

Is it object-oriented?

No, strictly speaking, no.

It's like object-oriented in VB6. It provides a nice encapsulation mechanism that you can use to separate data from methods, but it doesn't provide any inheritance, polymorphism, interfaces, or anything like that.

Clearly, it is a step forward in making javascript easier to maintain, parse and reuse.

Thomas Frank wrote a neat javascript library called classyJSON that adds features like inheritance and definition ranges to JSON code.

Is it just for client use?

Yes, and no. On the server side you can easily serialize objects to JSON and vice versa. For. net, programmers can automate these operations using libraries like Json.net (I guess using reflection), or you can do them yourself, which may be faster.

Three minutes is almost over…

I could only sort this out in a few minutes--all of which I said some things that might be completely wrong. If so, please leave a message and tell me how stupid I am. I'm happy to correct any mistakes. Good luck!

(Side note: if you replace {and} with "" and ":" with "/"…you get something very much like gaXml.) Interesting world.

(Note 2: Jason and Ajax are heroes of Greek mythology.) Preview: Other upcoming tech trash includes: Heracles, Perseus, Deucalian, Theseus and Bellerophon.)

Thank you for reading, the above is the content of "how to understand JSON", after the study of this article, I believe everyone has a deeper understanding of how to understand JSON this problem, the specific use of the situation still needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report