5

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.

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Agreed. I always find I make less silly errors when I serialize objects instead of hand building json.
This was fast! Right on time, thanks. Mine JSON message is really really big (this was small part of it). I was trying to construct json message using library but I got lost in the middle of it. So I use only this when I send message, but I parse answer from the server with Json library

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.