前端后端json技术整理

前端:

json对象,例如

var data = {
        c:100,
        person:[
            {name:"jack",age:18},
            {name:"tom",age:19},
            {name:"jerry",age:20},
            {name:"kid",age:21},
            {name:"jade",age:22}
        ]
    };

转化为,json串

JSON.stringify(pagination)

开始传输到后端

后端的json串返回到前端

在ajax请求,设置了

dataType:'json'            //期望返回的数据
contentType: 'application/json'//发送过去的数据
 

json串自动转成json对象

ps : js里面  json串和json对象互转方法

JSON.stringify(pagination) // json对象转json串
JSON.parse(temp)            //json串转json对象

 java的fastjson序列化和反序列化

String text = JSON.toJSONString(obj); //序列化
VO vo = JSON.parseObject("{...}", VO.class); //反序列化

 带有了泛型

List<VO> list = JSON.parseObject("...", new TypeReference<List<VO>>() {});


原文地址:https://www.cnblogs.com/vhyc/p/8434529.html