I have a code that generates a Json file in this format:
[
{
"$id": "1",
"poule": 73,
"idusuario": 4,
"vendedor": "ITAMAR SOUZA",
"total": 50.00,
"datajogo": "2016-01-19T00:00:00",
"terminal": "(11)985590116",
"empresa": "SANTIAGO - LOJA 01",
"nsu": 73
}
]
I'd like to write the output this way:
{
"venda":
[
{
"$id": "1",
"poule": 73,
"idusuario": 4,
"vendedor": "ITAMAR SOUZA",
"total": 50.00,
"datajogo": "2016-01-19T00:00:00",
"terminal": "(11)985590116",
"empresa": "SANTIAGO - LOJA 01",
"nsu": 73
}
]
}
This is the code:
[HttpGet]
[Route("consulta/ListarUltimoJogosRalizado/{idusuario}")]
public HttpResponseMessage ListarTodosJogosAtivos(int idusuario)
{
try
{
var tTabela = new JogoAplicacao();
var listar = tTabela.ListarPoId(idusuario);
return Request.CreateResponse(HttpStatusCode.OK, listar.ToArray());
}
catch (Exception ex)
{
return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
}
}
If the code is changed to:
return Request.CreateResponse(HttpStatusCode.OK, new { jogo = listar.ToArray() });
the return looks like this:
{
"$id": "1",
"venda": [
{
"$id": "2",
"poule": 73,
"idusuario": 4,
"vendedor": "ITAMAR SOUZA",
"total": 50.00,
"datajogo": "2016-01-19T00:00:00",
"terminal": "(11)985590116",
"empresa": "SANTIAGO - LOJA 01",
"nsu": 73
}
]
}