Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Remove invalid character \" from API JSON

(0) ShareShare
ReportReport
Posted on by 129
Hello experts,

I have created custom API and I am expecting following JSON format but I have received different format :
Looking your help to get the expected JSON (Extra  character added in JSON, how to remove  from the JSON to match the expected JSON)

Actual JSON format: Extra invalid character added in JSON



Expected JSON format:
 
Code:
 
        salesOrderList                            =  _request.ParmSalesOrder();
        ListEnumerator  ListLineEnumerator       =  salesOrderList.getEnumerator();
        while(ListLineEnumerator.moveNext())

      {
           salesOrderListContract = ListLineEnumerator.current();
            
            salesOrderLineResonse = new XXX_SalesOrderLineResonse();
            salesOrderLineResonse.parmOrderNum(salesOrderListContract.ParmSalesOrderList());
            orderList.addEnd(salesOrderLineResonse);
        }
        salesOrderResponse = new XXX_salesOrderResponse();
        salesOrderResponse.parmLine(orderList);
        
        str jsonSerializedContractResponse = FormJsonSerializer::serializeClass(salesOrderResponse); // convert the object to JSON response
   
       
        jsonSerializedContractResponse = strReplace(jsonSerializedContractResponse,/////, //);   //To remove backward slash and / from the output
       
        return jsonSerializedContractResponse;
 
Output: 
  • Verified answer
    Layan Jwei Profile Picture
    Layan Jwei 7,349 Super User 2024 Season 2 on at
    Remove invalid character \" from API JSON
    Hi KomalG,
     
    When you say custom API, do you mean custom service?
     
    If yes, then as Martain said, are you looking at debugger? Cause the result might be correct. Try to call the custom service vis postman for example and check if the result returned is correct or not (without the need to remove "\"
     
    Thanks,
    Layan Jweihan
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,445 Most Valuable Professional on at
    Remove invalid character \" from API JSON
    How are you checking the result? If you're looking at a variable in debugger, the whole problem may be in how the data is shown there. Try saving it to a file, for example.
     
    By the way, why are you trying to serialize the contract object by yourself? You should return the contract object from your custom service; F&O will do the serialization for 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans