예제 #1
0
            internal Task SaveAsync()
            {
                string json;

                lock (Mutex)
                    json = JsonProcessor.Encode(InternalDictionary);

                return(File.WriteToAsync(json));
            }
예제 #2
0
        /// <summary>
        /// Parses a JSON-text as defined in http://tools.ietf.org/html/rfc4627, returning an
        /// IDictionary&lt;string, object&gt; or an IList&lt;object&gt; depending on whether
        /// the value was an array or dictionary. Nested objects also match these types.
        /// </summary>
        public static object Parse(string input)
        {
            input = input.Trim();
            JsonProcessor parser = new JsonProcessor(input);

            if ((parser.ParseObject(out object output) || parser.ParseArray(out output)) && parser.CurrentIndex == input.Length)
            {
                return(output);
            }
            throw new ArgumentException("Input JSON was invalid.");
        }
예제 #3
0
            internal Task LoadAsync() => File.ReadAllTextAsync().ContinueWith(t =>
            {
                string text = t.Result;
                Dictionary <string, object> result = null;
                try { result = JsonProcessor.Parse(text) as Dictionary <string, object>; }
                catch (Exception) { }

                lock (Mutex)
                    InternalDictionary = result ?? new Dictionary <string, object> {
                    };
            });