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":[ "淘宝", "网购" ] }
    ]
}

你可能感兴趣的:(java)