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

How to enter a multiline string representing JSON into Visual Studio

If I enter this into Visual Studio editor, it is a mess and it doesn’t work as s is spread over multiple lines in the Editor and contains embedded " characters.

// This is my json string
string s = "
{
    "label": "MyLabel",
    "values": {
      "Key1": "Value1",
      "Key2": "Value2",
      "Key2": "Value3",
    }
}";

How do I annotate this with @ and \ so that is is a edit-time JSON string ?

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

>Solution :

Use a verbatim string using @"" and replace " with ""

Like this:

// This is my json string
string s = @"
{
    ""label"": ""MyLabel"",
        ""values"": {
        ""Key1"": ""Value1"",
        ""Key2"": ""Value2"",
        ""Key2"": ""Value3"",
    }
}
            ";
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