Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Json serialization x++ d365 fo

(0) ShareShare
ReportReport
Posted on by 22

Hi All,

I faced the issue about json serialization, i used this below code

str jsRead;

List resultSet = new List(Types::Class);

ResponseContract responseContract = new ResponseContract();
responseContract.parmRetTicketId("Test");
responseContract.parmRetStatus("Success");
responseContract.parmRetMessage("Test");
resultSet.addEnd(responseContract);

jsRead = FormJsonSerializer::serializeClass(resultSet);
return jsRead;

and i got the return like this

[{\"RetMessage\":\"Test\",\"RetStatus\":\"Success\",\"RetTicketId\":\"Test\"}]
How could it show this \ in the json string?
Regards,
Masha
  • Suggested answer
    Martin Dráb Profile Picture
    233,464 Most Valuable Professional on at
    RE: Json serialization x++ d365 fo

    It's true only in one case, not generally. Try using single quotation marks around the string literal, instead of double quotation marks - it doesn't require escaping and therefore it's easier to read:

    jsonStr = '{"name1":"%1"," name2":"%2"}';

  • Verified answer
    Blue Wang Profile Picture
    on at
    RE: Json serialization x++ d365 fo

    HI Masha,

    Combine the points mentioned above.

    If you want to write your own Json string manually (it is better to use JSON serializer instead of manual), then you need to add a backslash to the string.

    For example, use jsonStr = "{\"name1\":\"%1\",\"name2\":\"%2\"}"; instead of jsonStr ={"name1":"%1"," name2":"%2"};

  • Verified answer
    mhdshb1 Profile Picture
    1,250 on at
    RE: Json serialization x++ d365 fo

    Hi Masha,

    As Martin said, the backslashes are shown in the debugger watches and it is only for escaping the qutations.

    For example: 

    This is the printed json string 

    pastedimage1595330997151v1.png

    But in the debugger it looks like this

    pastedimage1595331037379v2.png

    "{\"_worker\":\"090344\",\"_dayDateFrom\":\"2020-06-07T00:00:00\",\"_dayDateTo\":\"2020-06-13T00:00:00\"}"

    Regards,

    M

  • Verified answer
    Martin Dráb Profile Picture
    233,464 Most Valuable Professional on at
    RE: Json serialization x++ d365 fo

    I suspect you're talking about the visualization in Visual Studio debugger and not the actual content of jsRead variable.

    The backslashes escape quotation marks, so you can copy the string and place it inside other quotations marks (as a string literal).

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 294 Most Valuable Professional

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 273

#3
Jonas "Jones" Melgaard Profile Picture

Jonas "Jones" Melgaard 177 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans