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

Does json belong to JavaScript?

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly shows you "json belongs to JavaScript", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "json belongs to JavaScript" this article.

Json belongs to JavaScript. Json is the string representation of JS object. It uses text to represent the information of a JS object. It is a lightweight data exchange format. Json format is the same as creating js object code in syntax. Json syntax is a subset of JS object literal representation syntax.

The operating environment of this tutorial: windows10 system, javascript1.8.5 version, Dell G3 computer.

The relationship between Json and Javascript

The data format of JSON is described by the representation of literal quantities of JS objects, so the syntax for describing JSON is a subset of the syntax of literal quantities of JS objects.

In fact, as to whether the attribute in the literal representation of js object is in quotation marks "js object" or "JSON object", it is a "js object" with or without quotation marks, but after you add quotation marks, it conforms to the grammatical rules of JSON, and the grammatical rules of JSON are a subset of the grammatical rules of "literal representation of js objects", so no matter how you express it. He is a "js object". So is there a situation where attributes have to be quoted? We know that js's naming rules for variables are numbers, letters, underscores and $symbols, and this rule applies to attributes without quotation marks, but if there are symbols other than these four in the attribute, such as "[" or "." Wait, the attribute must be represented in quotation marks.

In the final analysis, JSON is a data format and a specification for data, because it has self-descriptive and concise grammatical rules, which makes it an ideal format for data exchange between different languages. JSON exists independent of language, and any interpretation of it from the perspective of language and object is limited or wrong.

The difference between Json and Javascript

JSON is a string representation of a JS object, which uses text to represent the information of a JS object, which is essentially a string.

1. Var obj = {a: 'Hello', b:' World'}; / / this is an object. Note that key names can also be wrapped in quotation marks.

1. Var json ='{"a": "Hello", "b": "World"}'; / / this is a JSON string, which is essentially a string

JSON and JS objects convert to each other

To convert from an object to an JSON string, use the JSON.stringify () method:

1. Var json = JSON.stringify ({a: 'Hello', b:' World'}); / / the result is'{"a": "Hello", "b": "World"}'

To convert from JSON to an object, use the JSON.parse () method:

1. Var obj = JSON.parse ('{"a": "Hello", "b": "World"}'); / / the result is {a: 'Hello', b:' World'}

The above is all the content of the article "does json belong to JavaScript". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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: 223

*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