什么是jsonp_什么是json

什么是jsonp

JSON or JavaScript Object Notation is a format for storing and exchanging human-readable information. Although JSON began its distribution with JavaScript, it is supported in most languages, either natively or using special libraries. JSON is usually used for exchanging information between web clients and a web server.

JSON或JavaScript Object Notation是一种用于存储和交换人类可读信息的格式。 尽管JSON从JavaScript开始分发,但是大多数语言都支持JSON,无论是本机还是使用特殊库。 JSON通常用于在Web客户端和Web服务器之间交换信息。

In this article, you will learn what JSON is used for and how it can improve the performance of your site.

在本文中,您将学习JSON的用途以及它如何改善网站的性能。

JSON的作用是什么? (What is JSON used for?)

JSON is a format that stores structured information and is mainly used for data transfer between the server and the client.

JSON是一种存储结构化信息的格式,主要用于服务器和客户端之间的数据传输。

A JSON file is a simpler and easier alternative to an extension with similar XML functions

JSON文件是具有类似XML功能的扩展的更简单易用的替代方案

JSON语法(JSON syntax)

To create JSON correctly, you must follow the correct syntax.

要正确创建JSON,您必须遵循正确的语法。

There are two main elements of a JSON object: keys and values.

JSON对象有两个主要元素:键和值。

Keys must be strings. They contain a sequence of characters that are enclosed in quotes. The best way to create keys is camelCase.Values are a valid JSON data type. They can be in the form of an array, an object, a string, a Boolean value, a number, or a null value.

必须是字符串。 它们包含用引号引起来的一系列字符。 创建密钥的最佳方法是camelCase。 是有效的JSON数据类型。 它们可以采用数组,对象,字符串,布尔值,数字或空值的形式。

The JSON object starts and ends with brackets {}. Inside may be two or more pairs of keys/values with a comma for splitting them. Meanwhile, each key is followed by a colon to distinguish it from the value.

JSON对象以方括号{}开始和结束。 内部可能有两对或更多对键/值,并以逗号分隔。 同时,每个键后面都有一个冒号,以将其与值区分开。

For example:{“brand”:”BMW”, “model”:”320i“}

例如:{“ brand”:“ BMW”,“ model”:“ 320i”}

We have two key/value pairs: the keys are the brand and model; the BMW and 320i are the values.

我们有两个键/值对:键是品牌和型号。 宝马和320i是价值。

值类型 (Value type)

The values contain a valid JSON data type, for example:

这些值包含有效的JSON数据类型,例如:

数组 (Array)

An array is an ordered collection of values. It is enclosed in square brackets [], and each value inside is separated by a comma.

数组是值的有序集合。 它用方括号[]括起来,里面的每个值都用逗号分隔。

The array value can contain JSON objects, which means it uses the same concept of key/value pairs. For example:

数组值可以包含JSON对象,这意味着它使用相同的键/值对概念。 例如:

"articles":[      
{"creatorId":185, "creatorName":"Michael"},
{"creatorId":186, "creatorName":"John"},
{"creatorId":187, "creatorName":"Rob"},
]

The information in square brackets is an array containing three objects.

方括号中的信息是包含三个对象的数组。

目的 (Object)

The object contains a key and a value. Each key is followed by a colon, and each value is followed by a comma, which also distinguishes each object. Both of them are inside quotation marks.

该对象包含一个键和一个值。 每个键后跟一个冒号,每个值后跟一个逗号,也区分每个对象。 它们都在引号内。

The object as a value must follow the same rule as the object. For example:

对象作为值必须遵循与对象相同的规则。 例如:

airplane”: {"brand":"Cessna", "model":172}

Here, airplane are the key, and everything inside curly brackets is an object.

在这里,飞机是关键,大括号内的所有东西都是对象。

(String)

String — a specified sequence of zero or more Unicode characters enclosed in two double quotes.

String —由两个双引号引起来的零个或多个Unicode字符的指定序列。

This example shows that the volume represents a string because It is a set of characters inside double quotes.

此示例显示该卷代表一个字符串,因为它是双引号内的一组字符。

"brand":"Cessna"

(Number)

The number in JSON must be an integer or a floating point, for example:

JSON中的数字必须是整数或浮点数,例如:

"model":172

布尔型 (Boolean type)

You can use true or false as the value, as shown below:

您可以使用true或false作为值,如下所示:

"active":true

空值 (null)

Lack of information.

缺乏信息。

"deletedAt":null

存储的JSON数据 (Stored JSON Data)

You have two ways to store data: a JSON object and an array. The first one looks like this:

您有两种存储数据的方式:一个JSON对象和一个数组。 第一个看起来像这样:

airplane”: {
"brand":"Cessna",
"model":172
}

Curly brackets indicate that this is a JSON object. It includes two comma-separated key/value pairs.

圆括号指示这是一个JSON对象。 它包括两个逗号分隔的键/值对。

In each pair, you have keys (brand and model) followed by colons to distinguish them from values (Cessna, 172).

在每对中,您都有键(品牌和型号),后跟冒号以将它们与值区分开(Cessna,172)。

The values in this example are strings. This is why they are also enclosed in quotation marks, similar to keys.

此示例中的值是字符串。 这就是为什么它们也像关键字一样用引号引起来的原因。

使用数组 (Using Arrays)

Another way to store data is an array. Take a look at this example:

存储数据的另一种方法是数组。 看一下这个例子:

airplane”: {
"brand":"Cessna",
"model":172,
"pilots": ["Jack", "John", "Michael"]
}

What makes this method different from the previous one? So this is the fourth key/value pair. Pilots are a key, and there are several values in square brackets (Jack, John, Michael) that represent an array.

是什么使这种方法不同于以前的方法? 这是第四对键/值对。 飞行员是关键,方括号(Jack,John,Michael)中有多个表示数组的值。

结论 (Conclusion)

As you can see, JSON is a useful tool for data exchange. It has many advantages:

如您所见,JSON是用于数据交换的有用工具。 它具有许多优点:

It can load information asynchronously to make your site more responsive and handle the data flow better.It has an intuitive structureJSON is simpler and weighs less than XML.

它可以异步加载信息,以使您的站点响应速度更快,并更好地处理数据流。它具有直观的结构,JSON比XML更简单且重量更轻。

(.❛ ᴗ ❛.)

(.❛ᴗ。)

翻译自: https://medium.com/@kmorpex/what-is-json-2725bb91018e

什么是jsonp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值