This blog is useful to all my friends who are working on the .Net Technology and wants to enhance their skills as well their problem solving ability.

Monday, April 9, 2012

convert string to JSON object


 public static string ToJsonString(this string s)
        {
            return s.Replace(@"\", @"\\") // Escape \
                .Replace(@"""", @"\""") // Escape "
                .Replace("\n", "\\n") // Escape \n
                .Replace("\r", "") // Throw away \r
                .Replace("\t", "\\t");
        }

No comments: