ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

json使用类型

2021-05-04 17:59:00  阅读:16  来源: 互联网

标签:name 对象 nick json 数组 使用 类型 occupation


JSON使用类型

1、json值:

json值可以是:

  • 数字(整数或浮点数)
  • 字符串(在双引号中)
  • 布尔值(true或false)
  • 数组(在中括号中)
  • 对象(在大括号中)
  • null

(1)json数字:数字可以是整数或者浮点数

{
  "age":30,
  "score":99.5
}

(2)字符串:

{
  "name":"千叶",
  "profession":"程序员"
}

(3)布尔值:true或false

{
  "is_deleted":true
}

(4)数组:中括号中,数组可包括多个对象

//简单数据类型
["Porsche", "BMW", "Volvo" ]
[1,2,3]

//json对象中的数组
{
  "name":"qianye",
  "age":18,
  "cars":["Porsche","BMW","Volvo"]
}

//json对象中的数组可包括多个对象
{
  "name":"qianye",
  "age":18,
  "friends":[
    {"nick_name":"千叶结锤","occupation":"一位旅拍摄影师"},
    {"nick_name":"张三","occupation":"讲师"}
  ]
}

(5)对象:对象在大括号中{}书写

{
  "name":"千叶",
  "profession":"程序员",
  "hobby":"摄影"
}

(6)null

{ "runoob":null }

2、json使用javascript语法:

var data = [
  {"nick_name":"千叶结锤","occupation":"一位旅拍摄影师"},
  {"nick_name":"张三","occupation":"讲师"}
]

3、json对象

json对象语法

myObj = {"nick_name":"张三","occupation":"讲师"}

嵌套json对象:

{
  "name":"qianye",
  "age":18,
  "friends":[
    {"nick_name":"千叶结锤","occupation":"一位旅拍摄影师"},
    {"nick_name":"张三","occupation":"讲师"}
  ]
}

4、json数组

json数组语法:json数组在中括号中书写

[ "Google", "Runoob", "Taobao" ]

json对象中的数组

//json对象中的数组
{
  "name":"qianye",
  "age":18,
  "cars":["Porsche","BMW","Volvo"]
}

嵌套json对象中的数组:json对象中的数组可以包含另外一个数组,或者另外一个json对象

myObj = {
    "name":"网站",
    "num":3,
    "sites": [
      { "name":"Google", "info":[ "Android", "Google 搜索", "Google 翻译" ] },
      { "name":"Runoob", "info":[ "菜鸟教程", "菜鸟工具", "菜鸟微信" ] },
      { "name":"Taobao", "info":[ "淘宝", "网购" ] }
    ]
}

标签:name,对象,nick,json,数组,使用,类型,occupation
来源: https://blog.csdn.net/weixin_46377355/article/details/116402879

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有