locked
JSON formatting question? RRS feed

  • Question

  • User-1104215994 posted

    Hello,

    Here is my sample code portion. I am querying models and return the result.

    var gameBankResult = await (context.GameBanks.Where(g => g.productCode == initiate.productCode)
                    .Take(initiate.quantity)
                    .Select(g => new {
                        g.quantity,
                        g.currency,
                        g.initiationResultCode,
                        g.productCode,
                        g.productDescription,
                        g.referenceId,
                        g.responseDateTime,
                        g.unitPrice,
                        g.totalPrice,
                        Coupons = g.coupons.Select(c => new {c.Pin, c.Serial, c.expiryDate}).ToList() 
                    })).ToListAsync(); 
    
                if (gameBankResult.Count() != 0)
                {
                    
                    return Ok(JsonConvert.SerializeObject(gameBankResult));
                }

    But the problem is I am having this response:

    "[{\"quantity\":1,\"currency\":\"TRY\",\"initiationResultCode\":\"00\",\"productCode\":\"000000006446\",\"productDescription\":\"400 Riot Points - 400 RP\",\"referenceId\":null,\"responseDateTime\":null,\"unitPrice\":10.0,\"totalPrice\":10.0,\"Coupons\":[{\"Pin\":\"abcde\",\"Serial\":\"12345\",\"expiryDate\":null},{\"Pin\":\"jjjjj\",\"Serial\":\"77777\",\"expiryDate\":null}]}]"

    What I like is like this one:

    {
        "Id": 3031,
        "referenceId": "45000000450",
        "productCode": "000000006447",
        "quantity": 1,
        "version": "V1",
        "signature": "89d4dc5d4e6990af61ff05e3d423e437",
        "ApplicationCode": "52e7cf966b724749a7c4efadc3727ed7",
        "validatedToken": "",
        "responseDateTime": "2019-04-13T17:39:01.9541617+03:00",
        "initiationResultCode": "06",
        "companyToken": null,
        "estimateUnitPrice": "",
        "currency": ""
    }

    Saturday, April 13, 2019 2:45 PM

Answers