热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

json中的数据类型_JSON中的数据类型

json中的数据类型WeknowthatweuseJSONasamechanismandamediumtotransportdataontheweb.Insidethekey-va

json中的数据类型

We know that we use JSON as a mechanism and a medium to transport data on the web. Inside the key-value pairs, the JSON data has a predefined schema which tells us what types of data these values can manifest. In this article, we'll look at some common data types in JSON.

我们知道我们使用JSON作为一种机制和一种在Web上传输数据的媒介。 在键值对内部,JSON数据具有预定义的架构,该架构告诉我们这些值可以显示哪些数据类型。 在本文中,我们将研究JSON中的一些常见数据类型

主要类型 (Primary Types)

JSON data can assume the values to be any of the primary data types such as a string, number, integer, boolean constants or null. These can be in the form of the ordered or unordered list too in the form of objects and arrays but we'll explore them separately later. JSON Documents can be either basic values (strings, numbers, integers, the boolean constants or null). Thus the four basic value types supported by JSON Schema are,

JSON数据可以假定值是任何主要数据类型,例如字符串 , 数字 , 整数 , 布尔常量null 。 它们可以是有序列表或无序列表的形式,也可以是对象和数组的形式,但是我们稍后将分别进行探讨。 JSON文档可以是基本值( 字符串 , 数字 , 整数 , 布尔常量null )。 因此,JSON模式支持的四种基本值类型是:

  • String

  • Integer

    整数

  • Boolean

    布尔型

  • NULL

    空值

JSON字串 (JSON String)

The values in JSON data can be strings or simply a set of characters. We can also specify the entire document to have only the string schema too by writing,

JSON数据中的值可以是字符串,也可以只是一组字符。 我们还可以通过编写将整个文档指定为也只有字符串模式,

{"type": "string"}

All the characters must be enclosed inside double quotes and should be logically interpreted as a string to have the string schema,

所有字符必须用双引号引起来,并且在逻辑上应解释为具有字符串模式的字符串,

{"id": "101"}

The above JSON specified id to be a string but does not satisfy the string schema. Similarly,

上面的JSON将id指定为字符串,但不满足字符串架构。 同样,

{"flag": "true"}

It also specifies to be a string but yet again does not satisfy the string schema.

它还指定为字符串,但又一次不满足字符串模式。

{"name": "Ryan"}

Satisfied the string schema completely. There are certain restrictions we can impose on the string value. For instance, we specify the minimum and maximum length of our string,

完全满足字符串模式。 我们可以对字符串值施加某些限制。 例如,我们指定字符串的最小和最大长度,

{
"type": "string",
"minLength": 3,
"maxLength": 7
}

The above schema uses some string restrictions in JSON.

上面的架构在JSON中使用了一些字符串限制。

JSON编号 (JSON Number)

Another form of value in JSON are numbers. For example,

JSON中另一种形式的值是数字。 例如,

{"age": 45}

In JSON Schema we can also specify that a document must be a number by writing,

在JSON模式中,我们还可以通过以下方式指定文档必须为数字:

{"type": "number"}

Again as previously in a JSON Schema, the numeric value must only be a number and not a floating-point. However, inside the document, the value can be anything as long as it satisfies any one of the below-mentioned rules,

再次像以前在JSON模式中一样,数字值必须仅是数字,而不是浮点数。 但是,在文档内部,该值可以是任何值,只要它满足以下任一规则,

  1. It is represented in base 10 with no superfluous leading zeros.

    它以10为基数表示,没有多余的前导零。

  2. Digits are between 0 and 9.

    位数在0到9之间。

  3. It's a negative number or a fraction.

    这是一个负数或一个分数。

  4. It's an exponent of 10 prefixed by e.

    这是一个以e开头的10的指数。

{
"pages" : 210,
"temperature_kelvin" : -210,
"temperature_celcius" : 21.05,
"num" : 1.0E+2
}

The above JSON gives an example of the various kinds of numbers we can have. We can also specify the JSON schema to be an integer,

上面的JSON给出了我们可以拥有的各种数字的示例。 我们还可以将JSON模式指定为整数,

{"type": "integer"}

We can also have restrictions while using numbers in a JSON schema using maximum and minimum properties.

当在使用最大和最小属性的JSON模式中使用数字时,我们也会受到限制。

JSON布尔值 (JSON Booleans)

When a JSON value is a boolean it is either true or false without any quotes. If we put true and false within quotes it will be treated as a string.

如果JSON值为布尔值,则为true或false,且不带引号。 如果我们在引号中放入对与错,它将被视为一个字符串。

{"isPrime": true}

We can also specify the type to be Boolean inside a JSON schema,

我们还可以在JSON模式中将类型指定为布尔型,

{"type": "Boolean"}

JSON空 (JSON Null)

Values in JSON can also be null if they are expected to be empty.

如果JSON中的值应该为空,则也可以为null。

{"salary": null}

JSON values cannot be a function, date or undefined. We can use these data types to create JSON data, convert JSON data from one type to another and also generate JSON Schemas especially in a Nosequel type of databases like MongoDB, firebase, etc. We'll explore two more data types in JSON- arrays and objects separately.

JSON值不能是函数,日期或未定义。 我们可以使用这些数据类型来创建JSON数据,将JSON数据从一种类型转换为另一种类型,还可以生成JSON模式,尤其是在Nosequel类型的数据库(如MongoDB,firebase等)中。我们将在JSON数组中探索另外两种数据类型。和对象分开。

翻译自: https://www.includehelp.com/json/data-types-in-json.aspx

json中的数据类型



推荐阅读
  • 前景:当UI一个查询条件为多项选择,或录入多个条件的时候,比如查询所有名称里面包含以下动态条件,需要模糊查询里面每一项时比如是这样一个数组条件:newstring[]{兴业银行, ... [详细]
  • 电话号码的字母组合解题思路和代码示例
    本文介绍了力扣题目《电话号码的字母组合》的解题思路和代码示例。通过使用哈希表和递归求解的方法,可以将给定的电话号码转换为对应的字母组合。详细的解题思路和代码示例可以帮助读者更好地理解和实现该题目。 ... [详细]
  • Nginx使用(server参数配置)
    本文介绍了Nginx的使用,重点讲解了server参数配置,包括端口号、主机名、根目录等内容。同时,还介绍了Nginx的反向代理功能。 ... [详细]
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • 计算机存储系统的层次结构及其优势
    本文介绍了计算机存储系统的层次结构,包括高速缓存、主存储器和辅助存储器三个层次。通过分层存储数据可以提高程序的执行效率。计算机存储系统的层次结构将各种不同存储容量、存取速度和价格的存储器有机组合成整体,形成可寻址存储空间比主存储器空间大得多的存储整体。由于辅助存储器容量大、价格低,使得整体存储系统的平均价格降低。同时,高速缓存的存取速度可以和CPU的工作速度相匹配,进一步提高程序执行效率。 ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • 本文介绍了Python高级网络编程及TCP/IP协议簇的OSI七层模型。首先简单介绍了七层模型的各层及其封装解封装过程。然后讨论了程序开发中涉及到的网络通信内容,主要包括TCP协议、UDP协议和IPV4协议。最后还介绍了socket编程、聊天socket实现、远程执行命令、上传文件、socketserver及其源码分析等相关内容。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • Webpack5内置处理图片资源的配置方法
    本文介绍了在Webpack5中处理图片资源的配置方法。在Webpack4中,我们需要使用file-loader和url-loader来处理图片资源,但是在Webpack5中,这两个Loader的功能已经被内置到Webpack中,我们只需要简单配置即可实现图片资源的处理。本文还介绍了一些常用的配置方法,如匹配不同类型的图片文件、设置输出路径等。通过本文的学习,读者可以快速掌握Webpack5处理图片资源的方法。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 本文介绍了P1651题目的描述和要求,以及计算能搭建的塔的最大高度的方法。通过动态规划和状压技术,将问题转化为求解差值的问题,并定义了相应的状态。最终得出了计算最大高度的解法。 ... [详细]
  • 判断数组是否全为0_连续子数组的最大和的解题思路及代码方法一_动态规划
    本文介绍了判断数组是否全为0以及求解连续子数组的最大和的解题思路及代码方法一,即动态规划。通过动态规划的方法,可以找出连续子数组的最大和,具体思路是尽量选择正数的部分,遇到负数则不选择进去,遇到正数则保留并继续考察。本文给出了状态定义和状态转移方程,并提供了具体的代码实现。 ... [详细]
  • Linux环境变量函数getenv、putenv、setenv和unsetenv详解
    本文详细解释了Linux中的环境变量函数getenv、putenv、setenv和unsetenv的用法和功能。通过使用这些函数,可以获取、设置和删除环境变量的值。同时给出了相应的函数原型、参数说明和返回值。通过示例代码演示了如何使用getenv函数获取环境变量的值,并打印出来。 ... [详细]
author-avatar
kyf召世星bdc
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有