Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the correct format of Json string

I’am trying to display a Json string and I have some douts if my string is correct…

This is what i’ve done so far:

//defining tehe string
var test = "{\"data\":[[100.50, 170.00, \"13/04/2022\", \"Vigente\", 14, 15]]}";

//return my string
return Json(test);

//NOTE -- I'am using C# controler to make this work 

and this is what I have to follow —
Image that i trying to display like

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’am doing this right, if not whats is the right sintaxe to display that?

>Solution :

DO NOT ATTEMPT TO MANUALLY CREATE JSON

You should never attempt to generate JSON yourself like this as it is prone to errors. Anyway, Json() takes an object to serialize and will do it for you.

What you should do is:

var test = new {
    data = new List<List<object>>{
        new List<object>{ 100.50, 170.00, "13/04/2022", "Vigente", 14, 15 }
    }
};

return Json(test);

Even better would be to create a ViewModel object that you can populate instead of using an anonymous type.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading