Json传递数据两种方式
Posted 淡定
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Json传递数据两种方式相关的知识,希望对你有一定的参考价值。
@PostMapping(value = "/list")
@ResponseBody
public void invoiceDetail2(String ids) {
JSONObject jsonobject = JSONObject.parseObject(ids);
JSONArray jsonArray = JSONArray.parseArray(jsonobject.get("list1").toString());
List<String> list = jsonArray.toJavaList(String.class);
}
@PostMapping(value = "/list2")
@ResponseBody
public void list2(@RequestBody ScannerVo vo) {
List<String> list = vo.getList1();
// JSONArray jsonArray = JSONArray.parseArray(vo.getList1());
// List<String> list = jsonArray.toJavaList(String.class);
}
public class ScannerVo {
private List list1;
public List getList1() {
return list1;
}
public void setList1(List list1) {
this.list1 = list1;
}
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
private String test;
}
var getInvoice = function (invoiceCode,invoiceNum) {
var list1 = ["number","name"];
var param = {};
param["list1"] = list1;
param["test"] ="java";
var json = JSON.stringify(param);
$.ajax({
type: ‘POST‘,
url: CTX + ‘/checkInvoice/list2‘,
data: json,
dataType: "json",
async:false,
contentType: ‘application/json‘,
success: function(data){
if(data.success) {
value = ‘success‘;
$("#table").bootstrapTable(‘refresh‘);
} else {
value = ‘fail‘;
}
showAlertFrame(value, data.message);
},
error: function (e) {
}
});
};
以上是关于Json传递数据两种方式的主要内容,如果未能解决你的问题,请参考以下文章