Double quotation marks in string

If D365F&O, how does the escape characters work in x++ on a string? I’m trying to embed double quotes in a string, but the compiler keeps putting a slash in whatever I do. I have a string setup like below:

NameStr = “{“name”:”%1",“date”:"%2"}";

I want the string contents to look like this {“name”:"%1",“date”:"%2"}

If I just do NameStr = “{“name”:”%1",“date”:"%2"}"; the compiler will add the slashes.
I need to send this string to a webservice. How can I make this string come out without slashed?

Shawn

What do you mean by saying that compiler adds slashes? I don’t believe it’s true and you would have to examine the CIL code generated by the compiler, which isn’t likely, so I guess you’re talking about some kind of visualization and not the compiler output.

NameStr = “{“name”:”%1",“date”:"%2"}"; isn’t valid X++ code at all. It contains one string { followed by the identifier name, followed by another string : and so on. It’s clearly not what you wanted, even if it was possible to compile.

NameStr = “{“name”:”%1",“date”:"%2"}"; is valid and gives you what you want, but it can be written in an easier way: nameStr = ‘{“name”:"%1",“date”:"%2"}’;

Also, consider using a JSON serializer instead of composing JSON strings by yourself.

Martin, you are correct in that I was looking at the string values in the VS debugger which was showing the slashes. I will look at using a serializer instead of piecing a string together. Thank you for your response.

Shawn