vue axios qs.stringify() 生成的数据格式问题 ( 采用的是 application/x-www-form-urlencoded )
spring boot 后端出错 .
解决方法 用递归方式 convterJsonToFromData 生成对应的 from 表单提交的格式 .
<script >
var data = {
"contractId":"e19cb81856c14b13b2c386c0efec8b34",
"incomeList":[{
"type":"PLEDGE","money":33.33,"quantity":30.3,"lastQuantity":100
},{
"type":"PLEDGE","money":33.33,"quantity":30.3,"lastQuantity":100,test:{"name":"张三"}
}],
"quitList":[{
"type":"PLEDGE","money":33.33,"quantity":30.3,"lastQuantity":100
}]
};
print(convterJsonToFromData(data,""));
function convterJsonToFromData( data,keys,buffer){
if( buffer== null ){
buffer = [];
}
var type = (typeof data);
if(Array.isArray(data)){
for(var i = 0; i < data.length ;i++){
var newKeys = keys ? (keys +"[" +i+"]") : "[" +i+"]" ;
convterJsonToFromData(data[i],newKeys,buffer);
}
}else if( "object" == type ){
for(var key in data){
var newKeys = keys ? keys + "." + key : key;
convterJsonToFromData(data[key],newKeys,buffer)
}
}else{
buffer.push(keys + "=" + encodeURIComponent(data));
}
return buffer.join("&");
}
function print(s){
document.write("<h5>" +s+ "</h5>");
}
</script>