C # inserting variable into JSON string by escaping quotes

I have this JSON double quoted string and I want to insert the idValue variable inside

string json = @"  
{
    ""Request"": 
    {
       ""ElementList"": 
        {                                         
        ""id"": ""idValue""                                        
        }                         
     }
 }

      

In a normal string, this can be done with "+ idValue +", but how can I do it here when I have those double quotes? Thank.

+3


source to share


1 answer


You can do it:

string json = @"  
{
    ""Request"": 
    {
       ""ElementList"": 
        {                                         
        ""id"": "+ idValue + @"""                                        
        }                         
     }
 }";

      



But personally, I would rather use the Json library to back up my stuff.

+4


source







All Articles