예제 #1
0
 public JsonArray(IEnumerable collection)
 {
     foreach (var element in collection)
     {
         _jsonObjects.Add(JsonObjectFactory.BuildJsonObject(element.GetType(), element));
     }
 }
예제 #2
0
 public JsonClass(object obj)
 {
     foreach (var property in GetPropertiesToSerialize(obj))
     {
         this[property.Name.Surround("\"")] = JsonObjectFactory.BuildJsonObject(property.PropertyType, property.GetValue(obj));
     }
 }
예제 #3
0
        private void ParseProperties(JsonClass jsonClass, string json)
        {
            var matches = PropertyRegex.Matches(json);

            foreach (Match match in matches)
            {
                var name  = match.Groups["name"].Value;
                var value = match.Groups["value"].Value.Trim();
                jsonClass.Add(name, JsonObjectFactory.BuildJsonObject(value));
            }
        }
예제 #4
0
        public string Serialize(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            var jsonObject = JsonObjectFactory.BuildJsonObject(obj.GetType(), obj);

            return(jsonObject.ToString());
        }
예제 #5
0
        public string Serialize <T>(T obj) where T : class
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            var jsonObject = JsonObjectFactory.BuildJsonObject(typeof(T), obj);

            return(jsonObject.ToString());
        }
예제 #6
0
        public object Deserialize(Type type, string json)
        {
            if (string.IsNullOrEmpty(json) || json.Trim() == string.Empty)
            {
                throw new EmptyJsonException();
            }

            var jsonObject = JsonObjectFactory.BuildJsonObject(json);

            return(jsonObject.Materialize(type));
        }
예제 #7
0
        public JsonArray(string json)
        {
            var elements = json.
                           Substring(1, json.Length - 2)
                           .Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)
                           .Select(x => x.Trim())
                           .ToArray();

            foreach (var element in elements)
            {
                _jsonObjects.Add(JsonObjectFactory.BuildJsonObject(element));
            }
        }