0

I am trying to serialize my Entity model to JSON and I'm not sure if the return is correct.

public IHttpActionResult Get()
{
    using (var MGC = new GC_BranchNameEntities())
    {
        var serializer = new JsonSerializer();
        var jsonIDSA = JsonConvert.SerializeObject(MGC.INV_LIVE_IDSA, Formatting.None);
        try
        {
            return Ok(jsonIDSA);
        }
        catch (Exception e)
        {
            return BadRequest("Error occured when retreiving IDSA data " + e.Message);
        }
    }
}

This is what it return:

"[{\"id\":1,\"barcode\":\"TestBARCODE\",\"nsr\":0,\"stk_in\":0,\"stk_out\":0,\"sales\":0,\"balance\":1},{\"id\":2,\"barcode\":\"TestBARCODE2\",\"nsr\":0,\"stk_in\":0,\"stk_out\":0,\"sales\":0,\"balance\":1},{\"id\":3,\"barcode\":\"TestBARCODE3\",\"nsr\":0,\"stk_in\":0,\"stk_out\":0,\"sales\":0,\"balance\":1},{\"id\":4,\"barcode\":\"AAA\",\"nsr\":0,\"stk_in\":0,\"stk_out\":0,\"sales\":0,\"balance\":1},{\"id\":5,\"barcode\":\"BBB\",\"nsr\":0,\"stk_in\":0,\"stk_out\":0,\"sales\":0,\"balance\":1}]"

. I wasn't expecting a string with \ escapes. I am about to deserialize this in another project to use the values.

I was looking for something like this

[ {'id':1,'barcode':'TestBARCODE','nsr':0,'stk_in':0,'stk_out':0,'sales':0,'balance':1}, {'id':2,'barcode':'TestBARCODE2','nsr':0,'stk_in':0,'stk_out':0,'sales':0,'balance':1}, {'id':3,'barcode':'TestBARCODE3','nsr':0,'stk_in':0,'stk_out':0,'sales':0,'balance':1}, {'id':4,'barcode':'AAA','nsr':0,'stk_in':0,'stk_out':0,'sales':0,'balance':1}, {'id':5,'barcode':'BBB','nsr':0,'stk_in':0,'stk_out':0,'sales':0,'balance':1} ]

Serhiy Chupryk
  • 438
  • 2
  • 5
  • 15
J.P Masangcay
  • 759
  • 2
  • 10
  • 28
  • 1
    If you're debugging the project with Visual Studio, it's just the debugger view that shows the quotation marks escaped. – cbr Oct 20 '15 at 20:48

1 Answers1

0

This is correct! The backslashes are just used for escaping and this json should work fine.