Create JSON Payload Request Body?

ravidusing7

New member
Joined
Sep 15, 2023
Messages
1
Programming Experience
1-3
I do not have any idea how to create below JSON request below using C#

Below is the result set.

1694780533158.png



Below is the JSON payload i want to create using C#

{ "order_id": "10323730", "carton_no": "002", "qrcodes": { "F2VFN080": [ "lvs-d1PaZGmyfx", "7BhoKm4Hy1", "lvs-wGToHhv4zW" ], "F2VFN082": [ "bKQ9UuTzA3", "vs-EhnmkgBVdF" ], "F2VFN084": [ "fEdJRaVBSH", "A0MxquSd" ] } }

Please help me
 
Moving into C# general questions since this is not a VS.NET question.
 
Is there a particular JSON framework/library you are using or do you just want to built up that JSON payload using raw strings? Are you querying straight from the database using ADO.NET, or are your using some ORM or library?
 
Woohoo, you've sure started yourself off on a learning cliff there!

Try a simpler start, maybe..
 
Seeing that the OP has posted this same question both StackOverflow as well as Freelancer, it looks like this is a case of "gimme-the-codez". The OP doesn't seem to be interested in learning how to do something, but rather just wants the end result.
 
I do not have any idea how to create below JSON request below using C#

Below is the result set.

View attachment 2992


Below is the JSON payload i want to create using C#

{ "order_id": "10323730", "carton_no": "002", "qrcodes": { "F2VFN080": [ "lvs-d1PaZGmyfx", "7BhoKm4Hy1", "lvs-wGToHhv4zW" ], "F2VFN082": [ "bKQ9UuTzA3", "vs-EhnmkgBVdF" ], "F2VFN084": [ "fEdJRaVBSH", "A0MxquSd" ] } }

Please help me

So, install EF core power tools, use it to connect your db and reverse engineer this table

Use a query of

C#:
    var r = context.TestBatch.AsEnumerable()
      .GroupBy(t => t.OrderNumber)
      .Select(g => new{
        order_id = g.Key,
        carton_no = "002",
        qrcodes = g
          .GroupBy(t => t.ProductCode, t => t.URI, (k,g2) => (k,g2.ToArray()))
          .ToDictionary(u => u.Item1, u=>u.Item2)
      });

And then emit that from your controller with "return Ok(r)", or pass it to your json serializer like JsonConvert.SerializeObject(r);
 
Back
Top Bottom