Is it possible to change the format of the json file?

0

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
    }
  ]
}
    
asked by anonymous 22.01.2016 / 02:18

1 answer

1

Here's a solution:

return Request.CreateResponse(HttpStatusCode.OK, new { $id = 1, venda = listar.ToArray() } );

Ps: I posted the phone so I can not test the syntax but that's basically it

    
22.01.2016 / 02:22