Json Escape - CSharp System

CSharp examples for System:String Json

Description

Json Escape

Demo Code

// Permission is hereby granted, free of charge, to any person obtaining a copy
using System.Web;
using System.Text;
using System.Diagnostics.CodeAnalysis;
using System;//  w w  w  .j  a v a2 s  .com

public class Main{
        private static string JsonEscape(string escapee)
        {
            return escapee.Replace(@"\", @"\\")
                            .Replace(@"""", @"\""")
                            .Replace(@"/", @"\/")
                            .Replace(@"\b", @"\\b")
                            .Replace(@"\f", @"\\f")
                            .Replace(@"\n", @"\\n")
                            .Replace(@"\r", @"\\r")
                            .Replace(@"\t", @"\\t");
        }
}

Related Tutorials