示例#1
0
        private void WriteJsonProperty(string propertyName, object json)
        {
            if (json != null)
            {
                string jsonString = null;

                using (var writer = new TextJsonWriter())
                {
                    JsonSerializer.Write(json, writer);
                    if (!writer.IsEmpty)
                    {
                        jsonString = writer.ToString();
                    }
                }

                if (!string.IsNullOrWhiteSpace(jsonString))
                {
                    if (_commaNeeded)
                    {
                        WriteComma();
                    }

                    WritePropertyName(propertyName);
                    WriteJsonString(jsonString);

                    _commaNeeded = true;
                }
            }
        }
示例#2
0
 private void WriteJson(object json)
 {
     using (var writer = new TextJsonWriter())
     {
         JsonSerializer.Write(json, writer);
         WriteJsonString(writer.ToString());
     }
 }
示例#3
0
        /// <summary>
        /// Serializes the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">value</exception>
        public static string Serialize(T value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            using (var writer = new TextJsonWriter())
            {
                Write(value, writer);
                return(writer.ToString());
            }
        }
示例#4
0
        private void WriteJsonProperty(string propertyName, object json)
        {
            if (json != null)
            {
                string jsonString = null;

                using (var writer = new TextJsonWriter())
                {
                    JsonSerializer.Write(json, writer);
                    if (!writer.IsEmpty)
                    {
                        jsonString = writer.ToString();
                    }
                }

                if (!string.IsNullOrWhiteSpace(jsonString))
                {
                    if (_commaNeeded)
                    {
                        WriteComma();
                    }

                    WritePropertyName(propertyName);
                    WriteJsonString(jsonString);

                    _commaNeeded = true;
                }
            }
        }
示例#5
0
 private void WriteJson(object json)
 {
     using (var writer = new TextJsonWriter())
     {
         JsonSerializer.Write(json, writer);
         WriteJsonString(writer.ToString());
     }            
 }