I don't even know why but you need the @ sign beforehand...
The @
symbol in C# is called the Verbatim string operator. All it does is say to the compiler 'hey compiler, this string should be treated EXACTLY as it's written, no fancy stuff like turning \n into a new line!'
It allows you to write the string:
var path = "C:\\Users\\Deku\\Desktop;
as
var path = @"C:\Users\Deku\Desktop;
, increasing readability and preventing escape sequence errors like accidentally adding a new line.
how would you include the @ sign in a json file ?
For connection strings in your appsettings.json you would use traditional json format, just as you have listed. If any characters need to be prevented from escaping the string, such as the character \
you can simply put a \
before it to tell the string 'hey i want this character displayed as i typed it, do not turn it into something else.
However, with connection strings, yo won't normally need to do that since most connection strings are formatted without using escape sequences too often.
For example here's an appsettings.json showing my connection strings, don't worry the passwords aren't for production.
"ConnectionStrings": {
"DefaultConnection": "Data Source=mssql-server,1433;Initial Catalog=DingoAspnet;User ID=sa;Password=DingoChat5%;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
"DingoMessagesConnection": "Data Source=mssql-server,1433;Initial Catalog=DingoMessages;User ID=sa;Password=DingoChat5%;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
"DingoUsersConnection": "Data Source=mssql-server,1433;Initial Catalog=DingoUsers;User ID=sa;Password=DingoChat5%;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
},
Also make sure your curly braces ({}
) are facing the right way.
You have
> }
> "database": "Server = MYSQL, 455; Database = SomeDatabase; Trusted_Connection = True;"
> }
The first curly brace should be facing to the right. Marked here:
> { <----- this one
> "database": "Server = MYSQL, 455; Database = SomeDatabase; Trusted_Connection = True;"
> }