I want to send a Json with this format
{
"tarjetas": [
{"nombre":nombre, "id": id, "lista": lista, "idLista": idLista},
{"nombre":nombre, "id": id, "lista": lista, "idLista": idLista}
...
]
}
I build it like this:
var tarjetas = [];
var objeto = {};
tarjetas.push({
"nombre" : arrayCards[i],
"id" : arrayCardsId[i],
"nombreLista" : nombreLista,
"idLista": arrayCardsList[i]
});
objeto.tarjetas = tarjetas;
For this I have this code in Javascript with jQuery:
$.ajax({
type: "POST",
contentType : 'application/json; charset=utf-8',
dataType : 'json',
url: "http://localhost:8080/HelloSpringMVC/alo",
data: JSON.stringify(objeto),
success :function(result) {
// do what ever you want with data
}
Controller code:
@RequestMapping(value= "/j", method = RequestMethod.POST)
public String recibe(@RequestBody Tarjetas tarjeta){
System.out.println("Post");
System.out.println(tarjeta.toString());
return "index";
}
Class Cards:
public class Tarjetas {
private String tName;
private String tId;
private String nameList;
private String idList;
}
My problem is that I do not understand how to receive the Json in the controller, to work later with the data received, thanks.