I am trying to replace a string constant with an array of object.
What I have is
string test = "{\"property\":\"#replacedValue#\"}";
var array = someObject.where(x=>something).ToArray();
test = test.Replace("#replacedValue#",JsonConvert.SerializeObject(array));
output is coming as
{"property":"[{"name":"value"},{"name":"value"},{"name":"value"}]"}
Array is being replaced as string
what I want is
{"property":[{"name":"value"},{"name":"value"},{"name":"value"}]};
I am using .net core 3.1
#replacedValue#value, leaving the surrounding quotes in place. Replace the entire string instead ("#replacedValue#") escaping the double quotesstring test = {"property":"#replacedValue#"};this is not valid C#. What your probably have isstring test = "{\"property\":\"#replacedValue#\"}";