Beispiel #1
0
        public static string ToJsonString <T>(this IJsonFormatter <T> formatter, T value, IJsonFormatterResolver formatterResolver)
        {
            var writer = new JsonWriterUtf8();

            formatter.Serialize(writer, value, formatterResolver);
            return(writer.ToString());
        }
        public static string PrettyPrint(string json)
        {
            var reader = new JsonReaderUtf8(Encoding.UTF8.GetBytes(json));
            var writer = new JsonWriterUtf8(MemoryPool.GetBuffer());

            WritePrittyPrint(reader, writer, 0);
            return(writer.ToString());
        }
        public static string PrettyPrint(byte[] json, int offset)
        {
            var reader = new JsonReaderUtf8(json, offset);
            var writer = new JsonWriterUtf8(MemoryPool.GetBuffer());

            WritePrittyPrint(reader, writer, 0);
            return(writer.ToString());
        }
        public static string ToJsonString <T>(T value, IJsonFormatterResolver resolver)
        {
            if (resolver == null)
            {
                resolver = JsonSerializer.DefaultResolver;
            }

            var writer    = new JsonWriterUtf8(MemoryPool.GetBuffer());
            var formatter = resolver.GetFormatterWithVerify <T>();

            formatter.Serialize(writer, value, resolver);
            return(writer.ToString());
        }