Skip to main content

Notifications

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);

  • Martin Dráb Profile Picture
    232,938 Most Valuable Professional on at
    RE: Issue with the JSON String from JSON Service

    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.

  • Ian Hoyumpa Lavadia Profile Picture
    10 on at
    RE: Issue with the JSON String from JSON Service

    Hi Martin,

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

  • Ian Lavadia Profile Picture
    on at
    RE: Issue with the JSON String from JSON Service

    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

  • Verified answer
    Martin Dráb Profile Picture
    232,938 Most Valuable Professional on at
    RE: Issue with the JSON String from JSON Service

    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 Hoyumpa Lavadia Profile Picture
    10 on at
    RE: Issue with the JSON String from JSON Service

    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"
    }



  • Martin Dráb Profile Picture
    232,938 Most Valuable Professional on at
    RE: Issue with the JSON String from JSON Service

    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 Lavadia Profile Picture
    on at
    RE: Issue with the JSON String from JSON Service

    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

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 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,157 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,938 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans