pass json value which contain double quotes to our action method object

john john 1,021 Reputation points
2022-10-17T11:49:08.727+00:00

I have the following Action Method which accept a JSON object of type Info, inside my asp.net mvc-5:-

[HttpPost]  
public ActionResult UserInfo(Info info)  
{  

Info class

public class Info  
{  
public string username {get;set;}  
public string password {get;set;}  
}  

now i am testing this action method using FirFox RESTClient and PostMan.

now i can pass for example this JSON without any issues:-

251057-image.png

but let say the password contain double quotes inside it. and i pass it as \" then my action method will still read it as \" instead of " .. so i am not sure how to fix it? what type of encoding i need to apply to the json values before submitting them to the action method? or this need to be handled by the action method ? Thanks

Developer technologies | ASP.NET | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,926 Reputation points Volunteer Moderator
    2022-10-17T15:12:09.02+00:00

    You use json encoding, which is \” for double quotes. If you use the builtin json support it will be handled. If you print with the debugger, the debugger will again encode the value to display it. C# also uses \” for encoding.


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.