C # automatically outputs double quote character with backslash

I am writing a parser and website analyzer.

And I am creating a JSON object from the parsed parameters. For example, a website has a title Buy best phones from "NOKIA COMPANY LTD"

As you can see, the title has a double quote character: "

So when I parse the title, I get this:

Buy best phones from \"NOKIA COMPANY LTD\" and call anyone

Then I create a JSON object to be used by third party developers. I am using JSON newton soft library like this =

 var obj = new 
    { 
      Title = parsedTitle, 
      H1 = "some h1"
    };

      

JsonConvert.SerializeObject(obj, settings);

And like outside, I am getting invalid json, so frontend devs get error.

The JSON output will be something like this:

{
  "title": " Buy best phones from \\"
   NOKIA COMPANY LTD\\" and call anyone",
  "h1:: "some h1"
}

      

As you can see, this is not valid JSON. What should I do?

+3


source to share





All Articles