Esempio n. 1
0
        /// <summary>
        /// Deserializes object of the specified type from JSON string.
        /// </summary>
        /// <param name="type">The type of object to be deserialized.</param>
        /// <param name="json">The JSON string containing serialized object.</param>
        /// <param name="knownTypes">Collection of types that may be present in the object
        /// graph.</param>
        /// <param name="doPreProcessing">A value indicating whether pre-processing should be
        /// performed.</param>
        /// <returns>A reference to the deserialized object.</returns>
        public static object Deserialize(
            Type type,
            string json,
            IEnumerable <Type> knownTypes,
            bool doPreProcessing)
        {
            Debug.Assert(type != null);
            Debug.Assert(json != null);

            if (doPreProcessing)
            {
                json = JsonProcHelper.DoPreProcessing(json);
            }

            var serializer = new DataContractJsonSerializer(type, knownTypes);

            return(_Deserialize(serializer, json));
        }
Esempio n. 2
0
        /// <summary>
        /// Deserializes JSON object.
        /// </summary>
        /// <param name="json">String in JSON format.</param>
        /// <param name="doPreProcessing">
        /// A boolean value indicating whether pre-processing should be
        /// performed.
        /// </param>
        /// <param name="knownTypes">
        /// Types that may be present in the object graph. Can be null.
        /// </param>
        /// <returns>
        /// Deserialized object.
        /// </returns>
        public static T Deserialize <T>(string json, IEnumerable <Type> knownTypes,
                                        bool doPreProcessing)
        {
            Debug.Assert(json != null);

            // pre-processing
            if (doPreProcessing)
            {
                json = JsonProcHelper.DoPreProcessing(json);
            }

            T obj;

            if (knownTypes != null)
            {
                obj = Deserialize <T>(json, knownTypes);
            }
            else
            {
                obj = Deserialize <T>(json);
            }

            return(obj);
        }