Esempio n. 1
0
        /// <summary>
        /// Deserializes a JSON string into an object
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="json"></param>
        /// <returns>The deserialized JSON object</returns>
        public static T LoadFromString<T>(string json)
        {
            T returnValue;

            if (json != "")
            {
                TinyJSON.Variant variant = TinyJSON.Decoder.Decode(json);
                variant.Make<T>(out returnValue);

                return returnValue;
            }

            return default(T);
        }
Esempio n. 2
0
        /// <summary>
        /// Loads a JSON file from disk and deserializes its contents into an object
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="path"></param>
        /// <returns>The deserialized JSON object</returns>
        public static T Load<T>(string path)
        {
            T returnValue;

            if (path != "")
            {
                string readFile;

                using (System.IO.StreamReader file = new System.IO.StreamReader(path))
                {
                    readFile = file.ReadToEnd();
                }

                TinyJSON.Variant variant = TinyJSON.Decoder.Decode(readFile);
                variant.Make<T>(out returnValue);

                return returnValue;
            }

            return default(T);
        }