I'm trying to pass c# variables into the following string and I've got really lost around how to do it.
This is the string without the use of variables:
string data = @"{ ""fields"": {
""project"":
{
""key"": ""TEST""
},
""summary"": ""Test Ticket"",
""description"": ""test"",
""issuetype"": {""name"": ""test""},
""assignee"": { ""name"": ""test""}
}}";
Then when I try to include a variable (test.Text is a asp textbox) I do it this way:
string data = @"{ ""fields"": {
""project"":
{
""key"": ""TEST""
},
""summary"": ""Test Ticket"",
""description"": """ + test.Text + """,
""issuetype"": {""name"": ""test""},
""assignee"": { ""name"": ""test"" }
}}";
But that isn't working. Is there a different way to include variable data in there?
When I try and build it then it says
} expected.
So I went through and tried to wrap each one in } like this, but it didn't help :(
string data = @"{ ""fields"": {
""project"":
{
""key"": ""TEST""
},
""summary"": ""Test Ticket"",
""description"": {""" + test.Text + """},
""issuetype"": {""name"": ""test""},
""assignee"": { ""name"": ""test"" }
}}";
Thanks!
test.Texthas quotes etc in it.JsonConvert.+ test.Text + @"""},, but as have been said, the proper way to build json is not to do it with string concatenation, use a proper Json library for this.