コード例 #1
0
        private IComparable PerformArithmeticOperation(IEvaluable evaluable, IJSONDocument document, ArithmeticOperation operation)
        {
            IJsonValue value1, value2;

            if (!Evaluate(out value1, document))
            {
                return(null);
            }
            if (!evaluable.Evaluate(out value2, document))
            {
                return(null);
            }

            TypeCode      actualType1, actualType2;
            FieldDataType fieldDataType1 = JSONType.GetJSONType(value1.Value, out actualType1);
            FieldDataType fieldDataType2 = JSONType.GetJSONType(value2.Value, out actualType2);

            if (fieldDataType1.CompareTo(fieldDataType2) != 0)
            {
                return(null);
            }

            return(Evaluator.PerformArithmeticOperation(value1, actualType1, value2, actualType2, operation,
                                                        fieldDataType1));
        }
コード例 #2
0
        void CreateObject(JSONType type, string key)
        {
            JSON newObject = null;

            if (type == JSONType.Array)
            {
                newObject = new JSONArray();
            }
            else
            {
                newObject = new JSONObject();
            }
            if (_currentObject != null)
            {
                if (_currentObject.GetJSONType() == JSONType.Array)
                {
                    _currentObject.AsArray().Add(newObject);
                }
                else
                {
                    _currentObject.AsObject().Add(key, newObject);
                }
            }
            _stack.Push(newObject);
            _currentObject = newObject;
            MoveToNextNotEmptyPosition();
        }
コード例 #3
0
        public string ToJSON(JSONType type)
        {
            switch (type)
            {
            case JSONType.Create:
                break;

            default:
            case JSONType.Update:
                throw new System.ApplicationException("Unsupported JSONType for BCCaptionSource");
            }

            JSON.Builder builder = new JSON.Builder();

            // only consider writing: displayName and url

            builder.Append("{");
            builder.AppendField("displayName", displayName);
            if (!string.IsNullOrEmpty(url))
            {
                builder.Append(",").AppendField("url", url);
            }
            builder.Append("}");

            return(builder.ToString());
        }
コード例 #4
0
ファイル: JSONObject.cs プロジェクト: woniupapa/lockstep.io
 public void AddField(string name, JSONObject obj)
 {
     if (obj)
     {
         if (type != JSONType.OBJECT)
         {
             if (keys == null)
             {
                 keys = new List <string>();
             }
             if (type == JSONType.ARRAY)
             {
                 for (int i = 0; i < list.Count; i++)
                 {
                     keys.Add(i + "");
                 }
             }
             else if (list == null)
             {
                 list = new List <JSONObject>();
             }
             type = JSONType.OBJECT;
         }
         keys.Add(name);
         list.Add(obj);
     }
 }
コード例 #5
0
ファイル: JSONType.cs プロジェクト: uranium59/JSONGUIEditor
        static public string GetTypeString(this JSONType t)
        {
            switch (t)
            {
            case JSONType.Array:
                return("Array");

            case JSONType.Bool:
                return("Bool");

            case JSONType.Null:
                return("Null");

            case JSONType.Number:
                return("Number");

            case JSONType.Object:
                return("Object");

            case JSONType.String:
                return("String");

            default:
                return("");
            }
        }
コード例 #6
0
        private static string ToJSON(this BCPlaylist playlist, JSONType t)
        {
            //--Build Playlist in JSON -------------------------------------//

            Builder jsonPlaylist = new Builder(",", "{", "}");

            //id
            if (t.Equals(JSONType.Update))
            {
                jsonPlaylist.AppendObject("id", playlist.id.ToString());
            }

            //name
            if (!string.IsNullOrEmpty(playlist.name))
            {
                jsonPlaylist.AppendField("name", playlist.name);
            }

            //referenceId
            if (!string.IsNullOrEmpty(playlist.referenceId))
            {
                jsonPlaylist.AppendField("referenceId", playlist.referenceId);
            }

            //playlist type
            jsonPlaylist.AppendField("playlistType", playlist.playlistType.ToString());

            if (t.Equals(JSONType.Create))
            {
                //Video Ids should be a list of strings
                if (playlist.videoIds != null && playlist.videoIds.Count > 0)
                {
                    IEnumerable <string> values = from val in playlist.videoIds
                                                  select val.ToString();

                    jsonPlaylist.AppendObjectArray("videoIds", values);
                }
            }

            //filter tags should be a list of strings
            if (playlist.filterTags != null && playlist.filterTags.Count > 0)
            {
                jsonPlaylist.AppendStringArray("filterTags", playlist.filterTags);
            }

            //shortDescription
            if (!string.IsNullOrEmpty(playlist.shortDescription))
            {
                jsonPlaylist.AppendField("shortDescription", playlist.shortDescription);
            }

            //tagInclusionRule
            if (!string.IsNullOrEmpty(playlist.tagInclusionRule))
            {
                jsonPlaylist.AppendField("tagInclusionRule", playlist.tagInclusionRule);
            }

            return(jsonPlaylist.ToString());
        }
コード例 #7
0
ファイル: JSONObject.cs プロジェクト: woniupapa/lockstep.io
 public void Bake()
 {
     if (type != JSONType.BAKED)
     {
         str  = Print();
         type = JSONType.BAKED;
     }
 }
コード例 #8
0
ファイル: SelectTransform.cs プロジェクト: waqashaneef/NosDB
        public virtual IJSONDocument Transform(IJSONDocument document)
        {
            IJSONDocument newDocument;

            if (_criteria.GetAllFields)
            {
                newDocument = document.Clone() as IJSONDocument;
            }
            else
            {
                newDocument = JSONType.CreateNew();
            }

            //if (!_criteria.IsGrouped)
            //    newDocument.Key = document.Key;

            for (int i = 0; i < _criteria.ProjectionCount; i++)
            {
                IEvaluable field = _criteria[i];
                IJsonValue finalValue;

                if (field.Evaluate(out finalValue, document))
                {
                    //newDocument[field.ToString()] = finalValue.Value;
                    var binaryExpression = field as BinaryExpression;

                    if (binaryExpression != null)
                    {
                        if (binaryExpression.Alias != null)
                        {
                            newDocument[binaryExpression.Alias] = finalValue.Value;
                            continue;
                        }
                    }
                    newDocument[field.CaseSensitiveInString] = finalValue.Value;
                }
                else
                {
                    return(null);
                }
            }

            if (_criteria.ContainsOrder && !_criteria.IsGrouped)
            {
                _criteria.OrderByField.FillWithAttributes(document, newDocument);
            }
            else if (_criteria.IsGrouped)
            {
                _criteria.GroupByField.FillWithAttributes(document, newDocument);
            }

            if (newDocument.Count == 0)
            {
                return(null);
            }

            return(newDocument);
        }
コード例 #9
0
ファイル: JSONObject.cs プロジェクト: woniupapa/lockstep.io
 public void Absorb(JSONObject obj)
 {
     list.AddRange(obj.list);
     keys.AddRange(obj.keys);
     str  = obj.str;
     n    = obj.n;
     b    = obj.b;
     type = obj.type;
 }
コード例 #10
0
ファイル: JSON.cs プロジェクト: nyanzebra/JSON
 public JSONField(string value, JSONType type)
 {
     String_Value = value.Trim(Input.DOUBLE_QUOTES);
     JSON_Type    = type;
     if (type == JSONType.ARRAY || type == JSONType.OBJECT)
     {
         throw new JSONException("Inappropriate type for JSONField");
     }
 }
コード例 #11
0
        public int TestUpdateUserInfo(string user, string pass, string searchedUser, JSONType type)
        {
            Respuesta res = usrSrv.UpdateUserInfo(user, pass, searchedUser, getTestJSON(type));

            if (res.Code == 403)
            {
                usrSrv.DelteNode("usuarios_info/" + searchedUser);
            }
            return(res.Code);
        }
コード例 #12
0
    private string FilePathJSON(JSONType jsonType, string filenameTag = null)
    {
        string filename = jsonType.ToString();

        if (filenameTag != null)
        {
            filename = filename + "_" + filenameTag;
        }
        return(Path.Combine(_dirJSON, filename + ".json"));
    }
コード例 #13
0
ファイル: JSONObject.cs プロジェクト: NotYours180/lockstep.io
	public JSONObject(Dictionary<string, JSONObject> dic) 
	{
		type = JSONType.OBJECT;
		keys = new List<string>();
		list = new List<JSONObject>();
		foreach(KeyValuePair<string, JSONObject> kvp in dic) 
		{
			keys.Add(kvp.Key);
			list.Add(kvp.Value);
		}
	}
コード例 #14
0
ファイル: JSONObject.cs プロジェクト: woniupapa/lockstep.io
 public JSONObject(Dictionary <string, JSONObject> dic)
 {
     type = JSONType.OBJECT;
     keys = new List <string>();
     list = new List <JSONObject>();
     foreach (KeyValuePair <string, JSONObject> kvp in dic)
     {
         keys.Add(kvp.Key);
         list.Add(kvp.Value);
     }
 }
コード例 #15
0
 public JSONElement(JSONType type)
 {
     this.type = type;
     if (type == JSONType.LIST || type == JSONType.DIC)
     {
         this.data = new List <JSONElement>();
     }
     if (type == JSONType.DIC)
     {
         this.key = new List <string>();
     }
 }
コード例 #16
0
        private string getTestJSON(JSONType type)
        {
            string userInfoJSON = "";

            switch (type)
            {
            case JSONType.Valid:
                userInfoJSON = @"{
                                'correo': '*****@*****.**',
                                'nombre': 'Fulano Lopez',
                                'rol': 'ventas',
                                'telefono': '222-7-18-43-56'
                              }";
                break;

            case JSONType.Invalid:
                userInfoJSON = @"{
                                'correo': '*****@*****.**',                              
                                'rol': 'ventas',
                                'telefono': '222-7-18-43-56'
                              }";
                break;

            case JSONType.Malformed:
                userInfoJSON = @"{
                                'correo': '[email protected]                       
                                'rol': 'ventas',
                                'telefono': '222-7-18-43-56'
                              }";
                break;

            case JSONType.PartialValid:
                userInfoJSON = @"{
                                'correo': '*****@*****.**'
                              }";
                break;

            case JSONType.PartialInvalid:
                userInfoJSON = @"{
                                'correo': ''
                              }";
                break;

            case JSONType.PartialMalformed:
                userInfoJSON = @"{
                                'correo': '
                              }";
                break;
            }
            return(userInfoJSON);
        }
コード例 #17
0
        public override IEnumerable <KeyValuePair <AttributeValue, long> > Enumerate(QueryCriteria value)
        {
            IQueryStore   tempCollection = value.SubstituteStore;
            IJSONDocument doc            = JSONType.CreateNew();

            doc.Add("$count(*)", _count);
            doc.Key = Guid.NewGuid().ToString();
            tempCollection.InsertDocument(doc, null);
            var rowid = tempCollection.GetRowId(new DocumentKey(doc.Key));

            value.Store        = tempCollection;
            value.GroupByField = new AllField(Field.FieldType.Grouped);
            yield return(new KeyValuePair <AttributeValue, long>(NullValue.Null, rowid));
        }
コード例 #18
0
ファイル: JSONObject.cs プロジェクト: NotYours180/lockstep.io
	public JSONObject(JSONType t) 
	{
		type = t;
		switch(t) 
		{
			case JSONType.ARRAY:
				list = new List<JSONObject>();
				break;
			case JSONType.OBJECT:
				list = new List<JSONObject>();
				keys = new List<string>();
				break;
		}
	}
コード例 #19
0
ファイル: JSONObject.cs プロジェクト: woniupapa/lockstep.io
 public void Clear()
 {
     type = JSONType.NULL;
     if (list != null)
     {
         list.Clear();
     }
     if (keys != null)
     {
         keys.Clear();
     }
     str = "";
     n   = 0;
     b   = false;
 }
コード例 #20
0
ファイル: JSONObject.cs プロジェクト: woniupapa/lockstep.io
    public JSONObject(JSONType t)
    {
        type = t;
        switch (t)
        {
        case JSONType.ARRAY:
            list = new List <JSONObject>();
            break;

        case JSONType.OBJECT:
            list = new List <JSONObject>();
            keys = new List <string>();
            break;
        }
    }
コード例 #21
0
ファイル: JSONObject.cs プロジェクト: woniupapa/lockstep.io
 public void Add(JSONObject obj)
 {
     if (obj)
     {
         if (type != JSONType.ARRAY)
         {
             type = JSONType.ARRAY;
             if (list == null)
             {
                 list = new List <JSONObject>();
             }
         }
         list.Add(obj);
     }
 }
コード例 #22
0
ファイル: JSONIO.cs プロジェクト: nyanzebra/JSON
            private void handleFields(ref JSONObject root)
            {
                if (hasKey(File_Data[Index]))
                {
                    Key = extractKey(File_Data[Index]);
                    if (hasValue(File_Data[Index]))
                    {
                        string   value = extractFieldValue(File_Data[Index]);
                        JSONType type  = determineType(value);

                        if (isFieldType(type))
                        {
                            root.addField(Key, new JSONField(value, type));
                        }
                    }
                    Index++;
                }
            }
コード例 #23
0
ファイル: JSONObject.cs プロジェクト: woniupapa/lockstep.io
 public IEnumerable BakeAsync()
 {
     if (type != JSONType.BAKED)
     {
         foreach (string s in PrintAsync())
         {
             if (s == null)
             {
                 yield return(s);
             }
             else
             {
                 str = s;
             }
         }
         type = JSONType.BAKED;
     }
 }
コード例 #24
0
ファイル: JSONObject.cs プロジェクト: woniupapa/lockstep.io
    public static JSONObject Create(JSONType t)
    {
        JSONObject obj = Create();

        obj.type = t;
        switch (t)
        {
        case JSONType.ARRAY:
            obj.list = new List <JSONObject>();
            break;

        case JSONType.OBJECT:
            obj.list = new List <JSONObject>();
            obj.keys = new List <string>();
            break;
        }
        return(obj);
    }
コード例 #25
0
ファイル: SUM.cs プロジェクト: waqashaneef/NosDB
        public void ApplyValue(params object[] values)
        {
            if (values != null && values.Length > 0)
            {
                if (values[0] != null)
                {
                    FieldDataType type = JSONType.GetJSONType(values[0]);
                    switch (type)
                    {
                    case FieldDataType.Number:
                        _sum += Convert.ToDouble(values[0]);
                        break;

                    case FieldDataType.DateTime:
                        _sum += Convert.ToDateTime(values[0]).ToOADate();
                        break;
                    }
                }
            }
        }
コード例 #26
0
 public override IEnumerable <KeyValuePair <AttributeValue, long> > Enumerate(QueryCriteria value)
 {
     _filterDocument = JSONType.CreateNew();
     if (_childPredicates.Count > 0)
     {
         foreach (var childPredicate in _childPredicates)
         {
             var predicate = childPredicate as TerminalPredicate;
             if (predicate != null)
             {
                 foreach (var kvp in predicate.Enumerate(value))
                 {
                     _filterDocument.Clear();
                     PopulateDocument(kvp.Key, predicate.Source.Attributes);
                     if (_condition.IsTrue(_filterDocument))
                     {
                         yield return(kvp);
                     }
                 }
             }
         }
     }
 }
コード例 #27
0
        public override IJsonValue Evaluate(IJSONDocument document)
        {
            JSONResult result = (JSONResult)document;

            if (result != null)
            {
                IAggregation aggregation = result.GetAggregation(Name);
                if (aggregation != null)
                {
                    FieldDataType dataType = JSONType.GetJSONType(aggregation.Value);
                    switch (dataType)
                    {
                    case FieldDataType.Number:
                        return(new NumberJsonValue(aggregation.Value));

                    case FieldDataType.String:
                        return(new StringJsonValue((string)aggregation.Value));

                    case FieldDataType.Null:
                        return(new NullValue());

                    case FieldDataType.Object:
                        return(new ObjectJsonValue((IJSONDocument)aggregation.Value));

                    case FieldDataType.DateTime:
                        return(new DateTimeJsonValue((DateTime)aggregation.Value));

                    case FieldDataType.Bool:
                        return(new BooleanJsonValue((bool)aggregation.Value));

                    case FieldDataType.Array:
                        return(new ArrayJsonValue((IJsonValue[])aggregation.Value));
                    }
                }
            }
            return(base.Evaluate(document));
        }
コード例 #28
0
      public string ToJSON(JSONType type)
      {
         switch (type)
         {
            case JSONType.Create:
               break;

            default:
            case JSONType.Update:
               throw new System.ApplicationException("Unsupported JSONType for BCCaptionSource");
         }

         JSON.Builder builder = new JSON.Builder();

         // only consider writing: displayName and url

         builder.Append("{");
         builder.AppendField("displayName", displayName);
         if (!string.IsNullOrEmpty(url))
            builder.Append(",").AppendField("url", url);
         builder.Append("}");

         return builder.ToString();
      }
コード例 #29
0
ファイル: JSONObject.cs プロジェクト: NotYours180/lockstep.io
	public IEnumerable BakeAsync () 
	{
		if (type != JSONType.BAKED) 
		{
			foreach (string s in PrintAsync()) 
			{
				if (s == null)
				{
					yield return s;
				}
				else 
				{
					str = s;
				}
			}
			type = JSONType.BAKED;
		}
	}
コード例 #30
0
ファイル: JSONObject.cs プロジェクト: NotYours180/lockstep.io
	public void Bake() 
	{
		if (type != JSONType.BAKED) 
		{
			str = Print();
			type = JSONType.BAKED;
		}
	}
コード例 #31
0
ファイル: JSONObject.cs プロジェクト: NotYours180/lockstep.io
	public void Clear() 
	{
		type = JSONType.NULL;
		if(list != null)
		{
			list.Clear();
		}
		if(keys != null)
		{
			keys.Clear();
		}
		str = "";
		n = 0;
		b = false;
	}
コード例 #32
0
ファイル: JSONObject.cs プロジェクト: NotYours180/lockstep.io
	public JSONObject(double d) 
	{
		type = JSONType.NUMBER;
		n = d;
	}
コード例 #33
0
ファイル: JSONObject.cs プロジェクト: NotYours180/lockstep.io
	public JSONObject(bool b) 
	{
		type = JSONType.BOOL;
		this.b = b;
	}
コード例 #34
0
ファイル: JSONObject.cs プロジェクト: NotYours180/lockstep.io
	public void AddField (string name, JSONObject obj) 
	{
		if (obj) 
		{
			if (type != JSONType.OBJECT) 
			{
				if (keys == null)
				{
					keys = new List<string>();
				}
				if (type == JSONType.ARRAY) 
				{
					for (int i = 0; i < list.Count; i++)
					{
						keys.Add(i + "");
					}
				} 
				else if (list == null)
				{
					list = new List<JSONObject>();
				}
				type = JSONType.OBJECT;
			}
			keys.Add(name);
			list.Add(obj);
		}
	}
コード例 #35
0
        public override IEnumerable <KeyValuePair <AttributeValue, long> > Enumerate(QueryCriteria value)
        {
            IQueryStore tempCollection = value.SubstituteStore;
            var         key            = new DocumentKey();
            var         finalResultSet = new SortedDictionary <AttributeValue, long>();

            if (_childPredicates != null)
            {
                foreach (var childPredicate in _childPredicates)
                {
                    var predicate = childPredicate as TerminalPredicate;
                    if (predicate != null)
                    {
                        foreach (var kvp in predicate.Enumerate(value))
                        {
                            var newDocument = value.Store.GetDocument(kvp.Value, null);
                            if (newDocument == null)
                            {
                                continue;
                            }
                            AttributeValue newKey;
                            if (value.GroupByField.GetAttributeValue(newDocument, out newKey))
                            {
                                key.Value = newKey.ValueInString;

                                if (finalResultSet.ContainsKey(newKey))
                                {
                                    if (value.ContainsAggregations)
                                    {
                                        var groupDocument = tempCollection.GetDocument(finalResultSet[newKey], null);
                                        foreach (var aggregation in value.Aggregations)
                                        {
                                            IJsonValue calculatedValue;
                                            if (aggregation.Evaluation.Evaluate(out calculatedValue, newDocument))
                                            {
                                                aggregation.Aggregation.Value = groupDocument[aggregation.FieldName];
                                                aggregation.Aggregation.ApplyValue(calculatedValue.Value);
                                                groupDocument[aggregation.FieldName] = aggregation.Aggregation.Value;
                                            }
                                        }
                                        tempCollection.UpdateDocument(finalResultSet[newKey], groupDocument, new OperationContext());
                                    }
                                }
                                else
                                {
                                    var aggregateDocument = JSONType.CreateNew();
                                    value.GroupByField.FillWithAttributes(newDocument, aggregateDocument);
                                    if (value.ContainsAggregations)
                                    {
                                        foreach (var aggregation in value.Aggregations)
                                        {
                                            IJsonValue calculatedValue;
                                            if (aggregation.Evaluation.Evaluate(out calculatedValue, newDocument))
                                            {
                                                aggregation.Reset();
                                                aggregation.Aggregation.ApplyValue(calculatedValue.Value);
                                                aggregateDocument[aggregation.FieldName] = aggregation.Aggregation.Value;
                                            }
                                        }
                                    }

                                    aggregateDocument.Key = key.Value as string;
                                    tempCollection.InsertDocument(aggregateDocument,
                                                                  new OperationContext());
                                    long newRowId = tempCollection.GetRowId(key);
                                    finalResultSet.Add(newKey, newRowId);
                                }
                            }
                        }
                    }
                }
            }

            if (finalResultSet.Count == 0)
            {
                var emptyDoc = JSONType.CreateNew();
                if (value.ContainsAggregations)
                {
                    foreach (var aggregation in value.Aggregations)
                    {
                        emptyDoc[aggregation.FieldName] = 0;
                    }
                }
                key.Value    = value.GroupByField.FieldId.ToString();
                emptyDoc.Key = (string)key.Value;
                tempCollection.InsertDocument(emptyDoc, new OperationContext());
                finalResultSet.Add(new NullValue(), tempCollection.GetRowId(key));
            }
            value.Store = tempCollection;
            return(finalResultSet);
        }
コード例 #36
0
ファイル: JSONObject.cs プロジェクト: DaveSanders/jsontools
 public void SetImage()
 {
     if (this.ValueType != JSONType.Object && this.ValueType != JSONType.ObjectArray) { return; }
     if (this.ContainsOnlyObjects && this.ChildJSONObjects.Count > 1)
     {
         this.TreeNode.ImageIndex = 2;
         this.TreeNode.SelectedImageIndex = 2;
         this.ValueType = JSONType.ObjectArray;
     }
     else if (this.ContainsObjects)
     {
         this.TreeNode.ImageIndex = 0;
         this.TreeNode.SelectedImageIndex = 0;
         this.ValueType = JSONType.Object;
     }
     else
     {
         this.TreeNode.ImageIndex = 1;
         this.TreeNode.SelectedImageIndex = 1;
         this.ValueType = JSONType.Object;
     }
 }
コード例 #37
0
ファイル: JSONObject.cs プロジェクト: NotYours180/lockstep.io
	void Parse (string str, int maxDepth, bool storeExcessLevels, bool strict) 
	{
		if (!string.IsNullOrEmpty(str)) 
		{
			str = str.Trim(JSONWhitespace);
			if (strict) 
			{
				if(str[0] != '[' && str[0] != '{') 
				{
					type = JSONType.NULL;
					Debug.LogWarning("Improper (strict) JSON formatting.  First character must be [ or {");
					return;
				}
			}
			if (str.Length > 0) 
			{
				if (string.Compare(str, "true", true) == 0) 
				{
					type = JSONType.BOOL;
					b = true;
				} 
				else if (string.Compare(str, "false", true) == 0) 
				{
					type = JSONType.BOOL;
					b = false;
				} 
				else if (string.Compare(str, "null", true) == 0) 
				{
					type = JSONType.NULL;
				} 
				else if (str == JSONInfinity) 
				{
					type = JSONType.NUMBER;
					n = double.PositiveInfinity;
				} 
				else if (str == JSONNegativeInfinity) 
				{
					type = JSONType.NUMBER;
					n = double.NegativeInfinity;
				} 
				else if (str == JSONNotANumber) 
				{
					type = JSONType.NUMBER;
					n = double.NaN;
				} 
				else if (str[0] == '"') 
				{
					type = JSONType.STRING;
					this.str = str.Substring(1, str.Length - 2);
				} 
				else 
				{
					int tokenTmp = 1;
					int offset = 0;
					switch (str[offset]) 
					{
						case '{':
							type = JSONType.OBJECT;
							keys = new List<string>();
							list = new List<JSONObject>();
							break;
						case '[':
							type = JSONType.ARRAY;
							list = new List<JSONObject>();
							break;
						default:
							try 
							{
								n = System.Convert.ToDouble(str);
								type = JSONType.NUMBER;
							} 
							catch (System.FormatException) 
							{
								type = JSONType.NULL;
								Debug.LogWarning("improper JSON formatting:" + str);
							}
							return;
					}
					string propName = "";
					bool openQuote = false;
					bool inProp = false;
					int depth = 0;
					while (++offset < str.Length) 
					{
						if (System.Array.IndexOf(JSONWhitespace, str[offset]) > -1)
						{
							continue;
						}
						if (str[offset] == '\\') 
						{
							offset += 1;
							continue;
						}
						if (str[offset] == '"') 
						{
							if (openQuote) 
							{
								if (!inProp && depth == 0 && type == JSONType.OBJECT)
								{
									propName = str.Substring(tokenTmp + 1, offset - tokenTmp - 1);
								}
								openQuote = false;
							} 
							else 
							{
								if(depth == 0 && type == JSONType.OBJECT) 
								{
									tokenTmp = offset;
								}
								openQuote = true;
							}
						}
						if (openQuote)
						{
							continue;
						}
						if (type == JSONType.OBJECT && depth == 0) 
						{
							if(str[offset] == ':') 
							{
								tokenTmp = offset + 1;
								inProp = true;
							}
						}

						if(str[offset] == '[' || str[offset] == '{') 
						{
							depth++;
						} 
						else if (str[offset] == ']' || str[offset] == '}') 
						{
							depth--;
						}
						if ((str[offset] == ',' && depth == 0) || depth < 0) 
						{
							inProp = false;
							string inner = str.Substring(tokenTmp, offset - tokenTmp).Trim(JSONWhitespace);
							if(inner.Length > 0) 
							{
								if(type == JSONType.OBJECT)
								{
									keys.Add(propName);
								}
								if(maxDepth != -1)	
								{
									list.Add(Create(inner, (maxDepth < -1) ? -2 : maxDepth - 1));
								}
								else if (storeExcessLevels)
								{
									list.Add(CreateBakedObject(inner));
								}
							}
							tokenTmp = offset + 1;
						}
					}
				}
			} 
			else 
			{
				type = JSONType.NULL;
			}
		} 
		else 
		{
			type = JSONType.NULL;
		}
	}
コード例 #38
0
ファイル: JSONObject.cs プロジェクト: NotYours180/lockstep.io
	public static JSONObject Create (JSONType t) 
	{
		JSONObject obj = Create();
		obj.type = t;
		switch (t) 
		{
			case JSONType.ARRAY:
				obj.list = new List<JSONObject>();
				break;
			case JSONType.OBJECT:
				obj.list = new List<JSONObject>();
				obj.keys = new List<string>();
				break;
		}
		return obj;
	}
コード例 #39
0
ファイル: JSONObject.cs プロジェクト: NotYours180/lockstep.io
	public void Absorb (JSONObject obj) 
	{
		list.AddRange(obj.list);
		keys.AddRange(obj.keys);
		str = obj.str;
		n = obj.n;
		b = obj.b;
		type = obj.type;
	}
コード例 #40
0
ファイル: JSON.cs プロジェクト: JackSParrot/json-pkg
 protected JSON(JSONType type)
 {
     _parent = null;
     _type   = type;
 }
コード例 #41
0
ファイル: JSONObject.cs プロジェクト: DaveSanders/jsontools
 public void BuildTree(TreeView Tree)
 {
     Tree.Nodes.Clear();
     this.ValueType = JSONType.ObjectArray;
     this.TreeNode.Text = "Root";
     Tree.Nodes.Add(this.TreeNode);
     this.BuildTree();
     this.TreeNode.ExpandAll();
 }
コード例 #42
0
ファイル: JSONObject.cs プロジェクト: NotYours180/lockstep.io
	public void Add (JSONObject obj) 
	{
		if (obj) 
		{
			if (type != JSONType.ARRAY) 
			{
				type = JSONType.ARRAY;
				if (list == null)
				{
					list = new List<JSONObject>();
				}
			}
			list.Add(obj);
		}
	}
コード例 #43
0
ファイル: JSONObject.cs プロジェクト: NotYours180/lockstep.io
	public JSONObject (JSONObject[] objs) 
	{
		type = JSONType.ARRAY;
		list = new List<JSONObject>(objs);
	}
コード例 #44
0
        private static string ToJSON(this BCPlaylist playlist, JSONType t)
        {
            //--Build Playlist in JSON -------------------------------------//

            StringBuilder jsonPlaylist = new StringBuilder();

            //id
            if (t.Equals(JSONType.Update))
            {
                jsonPlaylist.Append("\"id\": " + playlist.id.ToString());
            }

            //name
            if (!string.IsNullOrEmpty(playlist.name))
            {
                if (jsonPlaylist.Length > 0)
                {
                    jsonPlaylist.Append(",");
                }
                jsonPlaylist.Append("\"name\": \"" + playlist.name + "\"");
            }

            //referenceId
            if (!string.IsNullOrEmpty(playlist.referenceId))
            {
                if (jsonPlaylist.Length > 0)
                {
                    jsonPlaylist.Append(",");
                }
                jsonPlaylist.Append("\"referenceId\": \"" + playlist.referenceId + "\"");
            }

            //thumbnailURL
            if (!string.IsNullOrEmpty(playlist.thumbnailURL))
            {
                if (jsonPlaylist.Length > 0)
                {
                    jsonPlaylist.Append(",");
                }
                jsonPlaylist.Append("\"thumbnailURL\": \"" + playlist.thumbnailURL + "\"");
            }

            //playlist type
            if (jsonPlaylist.Length > 0)
            {
                jsonPlaylist.Append(",");
            }
            jsonPlaylist.Append("\"playlistType\": \"" + playlist.playlistType.ToString() + "\"");

            if (t.Equals(JSONType.Create) || t.Equals(JSONType.Update))
            {
                //Video Ids should be a list of strings
                if (playlist.videoIds != null && playlist.videoIds.Count > 0)
                {
                    if (jsonPlaylist.Length > 0)
                    {
                        jsonPlaylist.Append(",");
                    }
                    jsonPlaylist.Append("\"videoIds\": [");
                    string append = "";
                    foreach (long id in playlist.videoIds)
                    {
                        jsonPlaylist.Append(append + "" + id.ToString() + "");
                        append = ",";
                    }
                    jsonPlaylist.Append("]");
                }
            }

            //filter tags should be a list of strings
            if (playlist.filterTags != null && playlist.filterTags.Count > 0)
            {
                if (jsonPlaylist.Length > 0)
                {
                    jsonPlaylist.Append(",");
                }
                jsonPlaylist.Append("\"filterTags\": [");
                string append = "";
                foreach (string tag in playlist.filterTags)
                {
                    jsonPlaylist.Append(append + "\"" + tag + "\"");
                    append = ",";
                }
                jsonPlaylist.Append("]");
            }

            //shortDescription
            if (!string.IsNullOrEmpty(playlist.shortDescription))
            {
                if (jsonPlaylist.Length > 0)
                {
                    jsonPlaylist.Append(",");
                }
                jsonPlaylist.Append("\"shortDescription\": \"" + playlist.shortDescription + "\"");
            }

            return("{" + jsonPlaylist.ToString() + "}");
        }
コード例 #45
0
ファイル: JSONObject.cs プロジェクト: uranium59/JSONGUIEditor
 public JSONObject()
 {
     type = State.JSONType.Object;
 }
コード例 #46
0
        private static string ToJSON(this BCVideo video, JSONType type)
        {
            //--Build Video in JSON -------------------------------------//

            StringBuilder jsonVideo = new StringBuilder();

            jsonVideo.Append("{");

            if (type.Equals(JSONType.Update))
            {
                //id
                jsonVideo.Append("\"id\": " + video.id.ToString() + ",");
            }

            //name
            if (!string.IsNullOrEmpty(video.name))
            {
                jsonVideo.Append("\"name\": \"" + video.name + "\"");
            }

            //shortDescription
            if (!string.IsNullOrEmpty(video.shortDescription))
            {
                jsonVideo.Append(",\"shortDescription\": \"" + video.shortDescription + "\"");
            }

            //Tags should be a list of strings
            if (video.tags.Count > 0)
            {
                jsonVideo.Append(",\"tags\": [");
                string append = "";
                foreach (string tag in video.tags)
                {
                    jsonVideo.Append(append + "\"" + tag + "\"");
                    append = ",";
                }
                jsonVideo.Append("]");
            }

            // Custom Fields should be a list of strings
            if (video.customFields.Values.Count > 0)
            {
                jsonVideo.Append(",\"customFields\": {");
                string append = "";
                foreach (string key in video.customFields.Values.Keys)
                {
                    jsonVideo.Append(append + "\"" + key + "\": \"" + video.customFields.Values[key] + "\"");
                    append = ",";
                }
                jsonVideo.Append("}");
            }

            //referenceId
            if (!string.IsNullOrEmpty(video.referenceId))
            {
                jsonVideo.Append(",\"referenceId\": \"" + video.referenceId + "\"");
            }

            //longDescription
            if (!string.IsNullOrEmpty(video.longDescription))
            {
                jsonVideo.Append(",\"longDescription\": \"" + video.longDescription + "\"");
            }

            if (!string.IsNullOrEmpty(video.linkText))
            {
                jsonVideo.Append(",\"linkText\": \"" + video.linkText + "\"");
            }

            if (!string.IsNullOrEmpty(video.linkURL))
            {
                jsonVideo.Append(",\"linkURL\": \"" + video.linkURL + "\"");
            }

            if (!string.IsNullOrEmpty(video.thumbnailURL))
            {
                jsonVideo.Append(",\"thumbnailURL\": \"" + video.thumbnailURL + "\"");
            }

            if (!string.IsNullOrEmpty(video.videoStillURL))
            {
                jsonVideo.Append(",\"videoStillURL\": \"" + video.videoStillURL + "\"");
            }

            if (video.cuePoints.Count > 0)
            {
                jsonVideo.Append(",\"cuePoints\": " + video.cuePoints.ToJSON());
            }

            //economics
            jsonVideo.Append(",\"economics\": \"" + video.economics.ToString() + "\"");

            // Start Date
            jsonVideo.Append(",\"startDate\": ");

            if (string.IsNullOrEmpty(video.startDate))
            {
                jsonVideo.Append("null");
            }
            else
            {
                jsonVideo.Append("\"" + video.startDate + "\"");
            }

            // End Date
            jsonVideo.Append(",\"endDate\": ");

            if (string.IsNullOrEmpty(video.endDate))
            {
                jsonVideo.Append("null");
            }
            else
            {
                jsonVideo.Append("\"" + video.endDate + "\"");
            }

            jsonVideo.Append("}");

            return(jsonVideo.ToString());
        }