热门标签 | 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中的数据类型



推荐阅读
  • 如何自行分析定位SAP BSP错误
    The“BSPtag”Imentionedintheblogtitlemeansforexamplethetagchtmlb:configCelleratorbelowwhichi ... [详细]
  • 电话号码的字母组合解题思路和代码示例
    本文介绍了力扣题目《电话号码的字母组合》的解题思路和代码示例。通过使用哈希表和递归求解的方法,可以将给定的电话号码转换为对应的字母组合。详细的解题思路和代码示例可以帮助读者更好地理解和实现该题目。 ... [详细]
  • 本文介绍了Python高级网络编程及TCP/IP协议簇的OSI七层模型。首先简单介绍了七层模型的各层及其封装解封装过程。然后讨论了程序开发中涉及到的网络通信内容,主要包括TCP协议、UDP协议和IPV4协议。最后还介绍了socket编程、聊天socket实现、远程执行命令、上传文件、socketserver及其源码分析等相关内容。 ... [详细]
  • Nginx使用(server参数配置)
    本文介绍了Nginx的使用,重点讲解了server参数配置,包括端口号、主机名、根目录等内容。同时,还介绍了Nginx的反向代理功能。 ... [详细]
  • PHP图片截取方法及应用实例
    本文介绍了使用PHP动态切割JPEG图片的方法,并提供了应用实例,包括截取视频图、提取文章内容中的图片地址、裁切图片等问题。详细介绍了相关的PHP函数和参数的使用,以及图片切割的具体步骤。同时,还提供了一些注意事项和优化建议。通过本文的学习,读者可以掌握PHP图片截取的技巧,实现自己的需求。 ... [详细]
  • SpringBoot uri统一权限管理的实现方法及步骤详解
    本文详细介绍了SpringBoot中实现uri统一权限管理的方法,包括表结构定义、自动统计URI并自动删除脏数据、程序启动加载等步骤。通过该方法可以提高系统的安全性,实现对系统任意接口的权限拦截验证。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • [译]技术公司十年经验的职场生涯回顾
    本文是一位在技术公司工作十年的职场人士对自己职业生涯的总结回顾。她的职业规划与众不同,令人深思又有趣。其中涉及到的内容有机器学习、创新创业以及引用了女性主义者在TED演讲中的部分讲义。文章表达了对职业生涯的愿望和希望,认为人类有能力不断改善自己。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • eclipse学习(第三章:ssh中的Hibernate)——11.Hibernate的缓存(2级缓存,get和load)
    本文介绍了eclipse学习中的第三章内容,主要讲解了ssh中的Hibernate的缓存,包括2级缓存和get方法、load方法的区别。文章还涉及了项目实践和相关知识点的讲解。 ... [详细]
  • http:my.oschina.netleejun2005blog136820刚看到群里又有同学在说HTTP协议下的Get请求参数长度是有大小限制的,最大不能超过XX ... [详细]
  • 本文介绍了为什么要使用多进程处理TCP服务端,多进程的好处包括可靠性高和处理大量数据时速度快。然而,多进程不能共享进程空间,因此有一些变量不能共享。文章还提供了使用多进程实现TCP服务端的代码,并对代码进行了详细注释。 ... [详细]
  • sklearn数据集库中的常用数据集类型介绍
    本文介绍了sklearn数据集库中常用的数据集类型,包括玩具数据集和样本生成器。其中详细介绍了波士顿房价数据集,包含了波士顿506处房屋的13种不同特征以及房屋价格,适用于回归任务。 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
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社区 版权所有