The json java string array to convert the leading end of the list

It was recorded at the front end of the string submitted by the array json ajax, how to convert a list at the rear end.

The request data into the distal end

var contracts = [
   ID {: '1', name: 'yanggb contract 1' },
   ID {: '2', name: 'yanggb contract 2' },
   ID {: '3', name: "Contract yanggb 3 ' },
   ID {: '4', name: 'yanggb contract 4' },
   ID {: '5', name: 'yanggb contract 5' }
];
$.ajax({
    type: 'post',
    url: 'contract\save',
    data: {contracts: JSON.stringify(contracts)},
    success: function() {
        console.log ( 'save the contract successfully!' );
    }
});

The front end by the JSON.stringify () method of the array into a JSON array of strings.

Accepts the request and the rear end of the data conversion

@PostMapping(value = "/contract/save")
@ResponseBody
public void saveContracts(String contracts) {
    List<Contract> contractList = JSON.parseArray(contracts, Contract.class);
    // 保存操作
}

JSON rear end is an array of strings by JSON.parseArray () method into a List, which accepts two parameters, the first parameter is a string JSON array, the second parameter is converted into a signature to the entity class object .

 

"You can overdraft, but always ashore."

Guess you like

Origin www.cnblogs.com/yanggb/p/11589405.html