Exemple #1
0
 public JsonArray(IEnumerable collection)
 {
     foreach (var element in collection)
     {
         _jsonObjects.Add(JsonObjectFactory.BuildJsonObject(element.GetType(), element));
     }
 }
Exemple #2
0
 public JsonClass(object obj)
 {
     foreach (var property in GetPropertiesToSerialize(obj))
     {
         this[property.Name.Surround("\"")] = JsonObjectFactory.BuildJsonObject(property.PropertyType, property.GetValue(obj));
     }
 }
        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));
            }
        }
        public string Serialize(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

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

            return(jsonObject.ToString());
        }
        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());
        }
        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));
        }
Exemple #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));
            }
        }