WCF anche JSON Format

F_Z_ 1 Reputation point
2021-11-17T14:51:23.797+00:00

Hello,
I've already created a WCF Web Service with .NET 4.5.1.
Accepts request is in JSON format.

I need for retrocompatibility accept a request like this: {Action:"bbb",Body:"bbb"}

I can notice that Action and Body doesn't have quotes.

How can I achieve this?

Now My Webservice accept only {"Action":"bbb","Body":"bbb"}

Thanks!

.NET
.NET
Microsoft Technologies based on the .NET software framework.
4,107 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 30,176 Reputation points Microsoft Vendor
    2021-11-18T03:27:22.2+00:00

    Hi @F_Z_ ,
    {Action: "bbb", Body: "bbb"} is a object.
    {"Action":"bbb","Body":"bbb"} is a JSON string.
    The conversion between the two can be achieved through the JSON.parse() and JSON.stringify() methods.

    console.log(JSON.stringify({Action:"bbb",Body:"bbb"}));  
    

    output

    '{"Action":"bbb","Body":"bbb"}'

    const json = '{"Action":"bbb","Body":"bbb"}';  
    const obj = JSON.parse(json);  
    console.log(obj);  
    

    output:

    Object { Action: "bbb", Body: "bbb" }

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.