web
You’re offline. This is a read only version of the page.
close
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

Issue with the JSON String from JSON Service

(0) ShareShare
ReportReport
Posted on by

Hi All,

I have a problem when deserializing the JSON String thrown by the D365FO using the JSON Service. I tried setting the header to Accept application/json.

pastedimage1578549231048v3.png

The class attached to the service:

[AifCollectionType('return', Types::RString, extendedTypeStr(Name))]

public anytype processData(ContractOfJsonReceived jReceived)

.

// Process Data

.

ContractOfJsonReturn jReturn;

str JSonStr = FormJsonSerializer::serializeClass(jReturn);

I have the same question (0)
  • Ian Lavadia Profile Picture
    on at

    By that way, the application I'm using to simulate pushing of data is Postman. And I do understand that people here would push me to develop this using NewtonSoft.JSON.Net on C# yet I want to know the workaround for this. Thank you

  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    You said you had a problem, but it's not clear to me what kind of problem.

    If you want to serialize the string to objects but you refuse to use the library doing exactly that, then what do you really want?

  • Ian Hoyumpa Lavadia Profile Picture
    10 on at

    Hi Martin,

    Sorry I wasn't able to describe more about my problem. The problem I encounter is that the response I received was enclosed with double quotes and the postman interprets it as a string. I'm hoping I can receive it as a JSON Object.

    Example: 

    "{\"Number Sequence\":123,\"Reference Number\":\"IHL | RMF-RAFI-PAY-RFP-000000236\"}"

    What I want to achieve is having a result of 


    {

    "Number Sequence":123,
    "Reference Number":"IHL-00002"
    }



  • Verified answer
    Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    A service operation returns data, which is then returned by the web service in JSON. Typically the data is a contract object and the web service returns this object serialized to JSON. But not in your case - instead of returning an object, you explicitly serialize it to a string and you return this string, therefore you get this string wrapped in JSON.

    The solution is throwing away your code with FormJsonSerializer and returning jReturn object directly. You'll also have to change the return type to ContractOfJsonReturn. And throw away AifCollectionType, because you're not returning a collection (such as a list of contract objects).

  • Ian Lavadia Profile Picture
    on at

    Hi Martin,

    Will check on this. Anyways I'm a huge fan of yours, I've learned a lot from your articles around here. Thank you very much

  • Ian Hoyumpa Lavadia Profile Picture
    10 on at

    Hi Martin,

    This is close my query on this thread. Thank you very much it is now working

  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    Then please mark reply (or replies) that answer the question. This will make clear that the thread doesn't need more answers and anybody finding the thread can easily find the solution.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 456 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans