简体   繁体   中英

c# inserting variable in JSON string by escaping quotes

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

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

In regular string this can be done by "+idValue+" ,but how I can do it here when I have these double quotes? Thanks.

You can do this :

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

But personally I'd prefer to use a Json library to stringify my stuff.

Edit: Added missing quotation marks in the string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM