Home Web Front-end JS Tutorial Summary of things to know about using JSON

Summary of things to know about using JSON

Apr 24, 2018 pm 05:18 PM
javascript json Summarize

This time I will bring you a summary of the instructions for using JSON. What are the precautions for using JSON? The following is a practical case, let's take a look.

Terms

Portability
Compatibility of transferring information between platforms and systems.

JSON
JavaScriptObjectNotation object notation.

Data exchange format
Text used to exchange data between different platforms or systems.

Literal value
The literal meaning is exactly the same as the value it wants to express.

Variable
is represented by an identifier in the shape of X and can be modified.

Maximum portability
Provides portability beyond the data format itself by ensuring the compatibility of the data itself with the platform and system.

Name-value pair
refers to attributes and characteristics (also called key-value pairs) that have names and corresponding values.

Syntax verification
Verification of json format.

Consistency verification
Focus on unique data structure verification.

String type in JSON
A string value, such as "You are a good person", is wrapped in double quotes.

concept

JSON is a data exchange format.

JSON is independent of programming languages.

JSON is based on the literal representation of JavaScript object (the emphasis is on the representation).

The way JSON expresses data is friendly to common programming concepts.

JSON is based on JavaScript object literalsThe syntax for representing properties, but does not include the function-related parts of JavaScript object literals.

In JSON name-value pairs, the name is always wrapped in double quotes.

JSON name-value pair, the value can be a string, number, Boolean value, null, object array.

Lists of name-value pairs in JSON are always wrapped in curly braces.

Multiple name value pairs in JSON are separated by commas.

JSON files use the .json extension.

The media type of JSON is application/json.

The Boolean type values ​​in JSON are only true and false, and all letters must be lowercase.

All letters of the null value in JSON must be lowercase, indicating a null value.

Number type in JSON, a numeric value, such as 66, can be a positive integer, a negative integer, a decimal, or an exponent.

The key difference between objects and arrays is that objects are lists or collections of name-value pairs, and arrays are lists and collections of values.

Another key difference between objects and arrays is that all values ​​in an array should have the same data type.

Terms
Arrays in JSON
An array is a collection or list of values, each value can be a string, number, boolean, object or in an array any type. Arrays must be wrapped in [] and separated by commas.

Object type in JSON
Object type is a collection of name-value pairs separated by commas and wrapped with {}.

JSON Schema
A virtual contract in data exchange.

Server side (in web development)

A series of operations performed on the server when web resources are requested. The server provides the Internet browser with responses that it processes and loads.

Client (in web development)
A series of operations performed when the interface requested by the browser is loaded, usually referring to HTML, CSS and JavaScript.

Concept
The JSON validator is responsible for validating syntax errors, and JSON Schema is responsible for providing consistency verification.

JSONSchema is the first line of defense responsible for data reception, and is also a good tool for the data sender to save time and ensure that the data is correct.

JSONSchema can solve the following consistency verification problems
1. Is the data type of the value correct? You can specify that a value is a number, string, etc. type.
 2. Does it contain the required data? You can specify which data is required and which is not.
 3. Is the form of the value what I need? You can specify a range, minimum value and maximum value.

JSON itself poses no threat, it is just text.

When locating JSON security issues, you should remember the following 3 things.
1. Do not use top-level arrays. Top-level arrays are legal JavaScript scripts. They can use < script> tag link and use.
 2. For resources that do not want to be made public, only the HTTPPost method is allowed to be requested, not the Get method. The get method can be requested through the url or even placed in the script tag.
 3. Use JSON.parser() instead of eval(). The eval() function will compile and execute the incoming string, which will make your code vulnerable to attacks. You should only use JSON.parser() to parse json data.

Security vulnerabilities are often caused by developers not considering how hackers could exploit this.

The relationship between JavaScript’s XMLHTTPRequest and WEBAPI is the relationship between the client and the server.

XMLHTTPRequest is not limited to XML, you can also use it to request JSON resources

Terms
Cross-site request forgery (CSRF)
refers to the use of site Attack the trust of the user's browser

Top-level JSON arrayA JSON array at the top of the document that exists outside of the JSON name-value pairs.

Injection attack
An attack that relies on injecting data into a web application to facilitate the execution or compilation of malicious data.

JSON cross-site scripting attack
An injection attack on the site by intercepting or replacing third-party code used in the site with malicious scripts.

webApi
A series of instructions and standards for interacting with services through HTTP.

XMLHTTPRequest
A JavaScript object that can obtain data from a URL without refreshing the page. It is commonly used in AJAX programming.

Hypertext Transfer Protocol (HTTP)
Basic protocol for exchanging data used by the World Wide Web

Serialization
The operation of converting objects into text

Deserialization
The operation of converting text into objects.

Concept
The website serves people, webAPI serves code, and they both use the Http protocol.

The same-origin policy makes it difficult for JavaScript and JSON resources to communicate client-server.

The client's cross-domain XMLHTTPRequest requires server support to ensure the success of the JSON resource request.

jQuery is an abstraction tool that provides JSON request and parsing functions that can shorten development time. It also solves cross-browser compatibility issues.

The concept of AngularJS MVC
JSON is a model||data model
HTML is a view and provides the syntax to bind to the model
The controller is AngularJS Syntax for defining and manipulating JavaScript files that interact with models and views.

AngularJS makes JavaScript objects and JSON shine in the MVC architecture.

In relational database, there are often table columns and rows and the relationship between them, in which primary keys and foreign keys are used.

There are many types of NoSQL databases, and they have different data storage and utilization methods from the traditional relational model.

Important concepts of CouchDB database
1. It is a document-oriented NoSQL database
2. It stores and manages JSON documents
3. It maintains data while storing and retrieving it Good data structure
4. It will use an HTTP-based API to obtain data as a JSON document resource
5. Ituses JavaScript as the query language and uses the map and reduce methods of the view Get data across APIs.

On the server side, JSON can be deserialized into objects and used in programming logic, or objects can be serialized into JSON format.

JSON is well supported by both the server and the client, making it stand out from many exchange data formats in the web field.

Terms
Same Origin Policy
For security reasons, the browser will only request scripts from the same domain.

Cross-domain resource sharing CORS
By setting the response header, cross-domain requests can be successful.

JSON-p
Use the script tag to bypass the same-origin policy restrictions and request JSON from servers with different domain names.

Abstraction
A technology for dealing with complex systems. The main idea is to convert a big problem into multiple small problems

Framework
A technology that can save time and has made We focus more on building abstract tools for functionality.

Jquery.parserJSON()
A jquery function, which not only calls the JSON.parser() function, but is also compatible with old browsers that do not support the JSON.parser() function, and passes the verification character to evaluate the string, thus avoiding possible security issues.

jquery.getJSON()
The short form of the jquery.ajax() function, which includes the function of parsing json into a JavaScript object.

Single-page web application
Different from the traditional multi-page method, it focuses on web pages that provide a more seamless application experience.

Model-View-Controller (MVC)
An application architecture pattern that divides the application into 3 parts: model (data), view (presentation), and controller (updating model and view) )

AngularJS
A JavaScriptMVC framework that uses JavaScript objects as data models.

Relational database
A database that stores stored data in a structured manner using identifiable relationships.

NoSQL database
A database that does not store relationships by storing data.

CouchDB
A document-oriented NoSQL database storage type that uses JSON documents to store data.

ASP.NET
Server-side Web framework developed by Microsoft

PHP
Server-side scripting language for creating dynamic web pages

Ruby on Rails
Server-side Web application framework written in Ruby

Node.js
Server-side JavaScript based on Google V8 engine.

java
An object-oriented programming language.

JSON will also serve as a static configuration file

When considering what data format to use, the form of the data and the system for exchanging the data should be considered. ! ! ! JSON is not always the best choice.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Adjustment of ajax execution order in jquery

Detailed explanation of Ajax and $.ajax instances

The above is the detailed content of Summary of things to know about using JSON. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Summarize the usage of system() function in Linux system Summarize the usage of system() function in Linux system Feb 23, 2024 pm 06:45 PM

Summary of the system() function under Linux In the Linux system, the system() function is a very commonly used function, which can be used to execute command line commands. This article will introduce the system() function in detail and provide some specific code examples. 1. Basic usage of the system() function. The declaration of the system() function is as follows: intsystem(constchar*command); where the command parameter is a character.

What is the difference between MySQL5.7 and MySQL8.0? What is the difference between MySQL5.7 and MySQL8.0? Feb 19, 2024 am 11:21 AM

MySQL5.7 and MySQL8.0 are two different MySQL database versions. There are some main differences between them: Performance improvements: MySQL8.0 has some performance improvements compared to MySQL5.7. These include better query optimizers, more efficient query execution plan generation, better indexing algorithms and parallel queries, etc. These improvements can improve query performance and overall system performance. JSON support: MySQL 8.0 introduces native support for JSON data type, including storage, query and indexing of JSON data. This makes processing and manipulating JSON data in MySQL more convenient and efficient. Transaction features: MySQL8.0 introduces some new transaction features, such as atomic

Performance optimization tips for converting PHP arrays to JSON Performance optimization tips for converting PHP arrays to JSON May 04, 2024 pm 06:15 PM

Performance optimization methods for converting PHP arrays to JSON include: using JSON extensions and the json_encode() function; adding the JSON_UNESCAPED_UNICODE option to avoid character escaping; using buffers to improve loop encoding performance; caching JSON encoding results; and considering using a third-party JSON encoding library.

Pandas usage tutorial: Quick start for reading JSON files Pandas usage tutorial: Quick start for reading JSON files Jan 13, 2024 am 10:15 AM

Quick Start: Pandas method of reading JSON files, specific code examples are required Introduction: In the field of data analysis and data science, Pandas is one of the important Python libraries. It provides rich functions and flexible data structures, and can easily process and analyze various data. In practical applications, we often encounter situations where we need to read JSON files. This article will introduce how to use Pandas to read JSON files, and attach specific code examples. 1. Installation of Pandas

How do annotations in the Jackson library control JSON serialization and deserialization? How do annotations in the Jackson library control JSON serialization and deserialization? May 06, 2024 pm 10:09 PM

Annotations in the Jackson library control JSON serialization and deserialization: Serialization: @JsonIgnore: Ignore the property @JsonProperty: Specify the name @JsonGetter: Use the get method @JsonSetter: Use the set method Deserialization: @JsonIgnoreProperties: Ignore the property @ JsonProperty: Specify name @JsonCreator: Use constructor @JsonDeserialize: Custom logic

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

In-depth understanding of PHP: Implementation method of converting JSON Unicode to Chinese In-depth understanding of PHP: Implementation method of converting JSON Unicode to Chinese Mar 05, 2024 pm 02:48 PM

In-depth understanding of PHP: Implementation method of converting JSONUnicode to Chinese During development, we often encounter situations where we need to process JSON data, and Unicode encoding in JSON will cause us some problems in some scenarios, especially when Unicode needs to be converted When encoding is converted to Chinese characters. In PHP, there are some methods that can help us achieve this conversion process. A common method will be introduced below and specific code examples will be provided. First, let us first understand the Un in JSON

Quick tips for converting PHP arrays to JSON Quick tips for converting PHP arrays to JSON May 03, 2024 pm 06:33 PM

PHP arrays can be converted to JSON strings through the json_encode() function (for example: $json=json_encode($array);), and conversely, the json_decode() function can be used to convert from JSON to arrays ($array=json_decode($json);) . Other tips include avoiding deep conversions, specifying custom options, and using third-party libraries.

See all articles