Beispiel #1
0
        public static string PrettifyJson(string json)
        {
            var pp        = new JsonPrettyPrinter();
            var sb_ugly   = new StringBuilder(json);
            var sb_pretty = new StringBuilder();

            pp.PrettyPrint(sb_ugly, sb_pretty);
            return(sb_pretty.ToString());
        }
Beispiel #2
0
        public static string Serialize(Object target, bool prettyPrint)
        {
            StringBuilder sbSerialized = new StringBuilder();
            JavaScriptSerializer js = new JavaScriptSerializer();

            js.Serialize(target, sbSerialized);

            if (prettyPrint)
            {
                StringBuilder prettyPrintedResult = new StringBuilder();
                prettyPrintedResult.EnsureCapacity(sbSerialized.Length);

                JsonPrettyPrinter pp = new JsonPrettyPrinter();
                pp.PrettyPrint(sbSerialized, prettyPrintedResult);

                return prettyPrintedResult.ToString();
            }
            else
                return sbSerialized.ToString();
        }
Beispiel #3
0
        public static string Serialize(Object target, bool prettyPrint)
        {
            StringBuilder        sbSerialized = new StringBuilder();
            JavaScriptSerializer js           = new JavaScriptSerializer();

            js.Serialize(target, sbSerialized);

            if (prettyPrint)
            {
                StringBuilder prettyPrintedResult = new StringBuilder();
                prettyPrintedResult.EnsureCapacity(sbSerialized.Length);

                JsonPrettyPrinter pp = new JsonPrettyPrinter();
                pp.PrettyPrint(sbSerialized, prettyPrintedResult);

                return(prettyPrintedResult.ToString());
            }
            else
            {
                return(sbSerialized.ToString());
            }
        }