I've tried everything but cannot seem to get a Variable into some text. I think the problem is that the test is in JSON format. I'm trying to pass a variable from a textbox in the UI to this variable, but for testing I've just created a local variable, as below. Here is my code:
Variable:
string Repo1 = "jamesbennett12345678990";
String I'm trying to add my variable into:
var UserAgent1 = new ProductInfoHeaderValue("ScraperBot", "1.0");
request.Headers.TryAddWithoutValidation("Authorization", "token testtesttesttest");
request.Headers.UserAgent.Add(UserAgent1);
//String here
request.Content = new StringContent("{\"name\":\"{Repo1}\"}");
I've read that to do this it is simply a case of putting curly braces around the variable but it doesnt work. I know this because the line - string Repo1 = "jamesbennett12345678990"; says that the variable is not in use.
This part is JSON Data that is getting passed using the HTPClient so I'm thinking as there are already Speachmarks escaped with backslashes that there might be a formatting problem here ---- ("{"name":"{Repo1"}")
I don't have any errors as such, only the one in VS saying the
var string Repo1 = "jamesbennett12345678990";
isn't actually in use.
I've also looked into string Interpolation.


$"foo {bar} baz"with JSON syntax.new StringContent($"\{\"name\":\"{Repo1}\"\}");and escape the curly braces that are not representing a variable.new StringContent($@"{{""name"":""{Repo1}""}}");. If you want to get a serializer to form it,JsonConvert.SerializeObject(new{name=Repo1});(Newtonsoft) orJsonSerializer.Serialize(new { name = Repo1 });(STJ) - personally I'd go the latter route of "use a serializer lib". You've bought a dog, don't bark yourself