I have been trying to import a JSON string into VB.NET just to experiment with an http client I am working with, this is a throw away exercise but it will allow me to confirm some puzzling functionality I am experiencing. The JSON is:
{
"BoundaryType": "Outside",
"StartTime": "2022-12-07T00:00:00",
"EndTime": "2022-12-08T00:00:00",
"TagFilter": "atagname",
"Delimiter":"",
"ServerName": "aservername"
}
Trying to replicate this in VB.NET as a plain string is proving to be a RPITA. No matter what I do VB.NET does not seem to want to allow me to concatenate a single double quote. I have even resorted to altering the JSON to supplanting the double quotes with ‘!’ as a placeholder and then replacing with double quotes as in:
{
!BoundaryType!: !Outside!,
!StartTime!: !2022-12-07T00:00:00!,
!EndTime!: !2022-12-08T00:00:00!,
!TagFilter!: !atagname!,
!Delimiter!:!!,
!ServerName!: !aservername!
}
content = content.Replace("!", Chr(34))
But this still results in:
{
""BoundaryType"": ""Outside"",
""StartTime"": ""2022-12-07T00:00:00"",
""EndTime"": ""2022-12-08T00:00:00"",
""TagFilter"": ""atagname"",
""Delimiter"":"""",
""ServerName"": ""aservername""
}
Curiously enough if I view this in the Text Visualizer in Visual Studio it displays what I want:
{
"BoundaryType": "Outside",
"StartTime": "2022-12-07T00:00:00",
"EndTime": "2022-12-08T00:00:00",
"TagFilter": "atagname",
"Delimiter":"",
"ServerName": "aservername"
}
but passed as a variable into a function I get the repeated double quotes.
3
Answers
I think on reflection probably avoiding the hassle with quotes entirely (JimC's response) is the way to go. Thanks all for your feedback.
Use "" to insert double quotes in a string:
If you want to avoid the problem entirely, you can use tags to define the string:
Code:
Class: