1JSON的格式与解析
json是一种与语言无关的数据交换格式。作用:使用ajax进行前后台数据交换,移动端与服务端的数据交换
1>对象格式:{“key1”:obj,"key2",obj,"key3":obj....}
2>数组格式:[obj,obj,obj......]
eg:一个user对象用json数据格式表示
{"username":"zhangsan","age":24,"address":"beijing","account":{"money":88888,"time":"2018-7-12"}}
eg:List<Person>
[{"username":"zhangsan","age":24,"address":"beijing","account":{"money":88888,"time":"2018-7-12"},{"username":"lisi","age":20,"address":"wuhan","account":{"money":10000,"time":"2018-7-12"},{"username":"wangwu","age":29,"address":"zhengzhou","account":{"money":26000,"time":"2017-7-12"}]
注意:对象格式与数组格式可以互相嵌套
json的解析:
json是js的原生内容,即js可以直接取出json对象中的数据
2Json转换插件
将Java对象或集合转换成json形式字符串
转换工具:
1>jsonlib
2>Gson:google
3>fastjson:阿里巴巴