JSON(JavaScript Object Notation,JS对象标记)是一种轻量级的数据交换格式。

目录

1、json格式

为{k:v},这个是一个键值对的json串;JSON中k都为String格式,v可以为Object、数组和集合,举例1如下:

举例2:Value为数组

{undefined

“employees”: [

{ “firstName”:”Bill” , “lastName”:”Gates” },

{ “firstName”:”George” , “lastName”:”Bush” },

{ “firstName”:”Thomas” , “lastName”:”Carter” }

]

}

json在线格式(json格式示例)_json在线格式

案例一:

  {key:value,key:value}

​​

class Person{
         
         
String firstname = "张";
String lastname = "三丰";
Integer age = 100;
}

Person p = new Person();
System.out.println(p.firstname);

转JS:

var person = {"firstname":"张","lastname":"三丰","age":100};

//取出lastname
alert(person.lastname);
//取出age
alert(person.age);