示例#1
0
        /// <summary>
        /// Parses JSON read from the given text reader and converts
        /// it to a generic JsonValue.
        /// </summary>
        /// <param name="reader">The TextReader to read JSON from.</param>
        /// <returns>The generic JsonValue.</returns>
        public static JsonValue Parse(TextReader reader)
        {
            JsonValueJsonConsumer valueParser = new JsonValueJsonConsumer();

            Parse(reader, valueParser);
            return(valueParser.Result);
        }
示例#2
0
        /// <summary>
        /// Converts the given .NET object to the generic JSON object model represented
        /// by <see cref="JsonValue"/> and deriving classes.
        /// </summary>
        /// <param name="model">The .NET object to read from.</param>
        /// <returns>The resulting <see cref="JsonValue"/>.</returns>
        public static JsonValue FromModel(object model)
        {
            if (model == null)
            {
                return(new JsonNull());
            }

            var        consumer  = new JsonValueJsonConsumer();
            IConverter converter = ConverterRegistry.Get(model.GetType());

            converter.Write(model, consumer);
            return(consumer.Result);
        }