예제 #1
0
        private void CollectValue(JsonToken jtoken)
        {
            var item = new JsonValue(jtoken.Type, jtoken.Value);

            //вариант с автономным значением
            if (null == rootitem)
            {
                rootitem    = item;
                currentitem = item;
                return;
            }

            //вариант выставления свойства значению
            if (null != currenttuple)
            {
                currenttuple.Value = item;
                (currentitem as JsonObject).Properties.Add(currenttuple);
                currenttuple = null;
                //пока еще не было запятой - нельзя новые значения
                currentitem.CanAddItems = false;
                return;
            }

            //вариант с массивом
            if (currentitem is JsonArray)
            {
                (currentitem as JsonArray).Values.Add(item);
                //пока нет запятых - нельзя новые значения
                currentitem.CanAddItems = false;
                return;
            }

            throw new Exception("insuficient place of value");
        }
예제 #2
0
 private void CollectName(JsonToken jsonToken)
 {
     if (currentitem is JsonObject && null == currenttuple)
     {
         currenttuple      = new JsonTuple();
         currenttuple.Name = new JsonValue(jsonToken.Type, jsonToken.Value);
         return;
     }
     throw new Exception("insuficient place of name");
 }
예제 #3
0
 /// <summary>
 /// Возвращает значение свойства по коду
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public JsonItem this[string name] {
     get {
         if (!Contains(name))
         {
             return(null);
         }
         return(Properties.First(_ => _.Name.Value == name).Value);
     }
     set {
         var property = Properties.FirstOrDefault(_ => _.Name.Value == name);
         if (null == property)
         {
             property = new JsonTuple {
                 Name = new JsonValue(JsonTokenType.String, name)
             };
             Properties.Add(property);
         }
         property.Value = value;
     }
 }
예제 #4
0
        private void ProcessOpenArray(JsonToken jsonToken)
        {
            if (!CanSetValue())
            {
                throw new Exception("cannot open array here");
            }
            var newobj = new JsonArray();

            // вариант с корневым объектом
            if (null == rootitem)
            {
                rootitem    = newobj;
                currentitem = newobj;
                return;
            }

            // вариант с значением свойства
            if (null != currenttuple && currenttuple.HasColon)
            {
                newobj.Parent      = currentitem;
                currenttuple.Value = newobj;
                (currentitem as JsonObject).Properties.Add(currenttuple);
                currenttuple = null;
                currentitem  = newobj;
                return;
            }

            if (currentitem is JsonArray && currentitem.CanAddItems)
            {
                newobj.Parent = currentitem;
                (currentitem as JsonArray).Values.Add(newobj);
                currentitem = newobj;
                return;
            }
            throw new Exception("cannot open object here");
        }