Exemplo n.º 1
0
        public void IndexOf()
        {
            object v1 = 1;
            object v2 = 2;
            object v3 = 3;

            JsonArray j = new JsonArray();
            j.Add(v1);

            Assert.AreEqual(0, j.IndexOf(v1));

            j.Add(v2);
            Assert.AreEqual(0, j.IndexOf(v1));
            Assert.AreEqual(1, j.IndexOf(v2));
        }
Exemplo n.º 2
0
 public static string Params2Json(params object[] objs)
 {
     JsonArray json = new JsonArray();
     foreach (object obj in objs)
     {
         json.Add(obj);
     }
     return json.ToString();
 }
Exemplo n.º 3
0
        public void Insert()
        {
            object v1 = 1;
            object v2 = 2;
            object v3 = 3;
            object v4 = 4;

            JsonArray j = new JsonArray();

            j.Add(v1);
            j.Add(v2);
            j.Add(v3);
            j.Insert(1, v4);

            Assert.AreEqual(0, j.IndexOf(v1));
            Assert.AreEqual(1, j.IndexOf(v4));
            Assert.AreEqual(2, j.IndexOf(v2));
            Assert.AreEqual(3, j.IndexOf(v3));
        }
Exemplo n.º 4
0
        public void Remove()
        {
            object v = 1;
            JsonArray j = new JsonArray();
            j.Add(v);

            Assert.AreEqual(1, j.Count);

            Assert.AreEqual(false, j.Remove(2));
            Assert.AreEqual(false, j.Remove(null));
            Assert.AreEqual(true, j.Remove(v));
            Assert.AreEqual(false, j.Remove(v));

            Assert.AreEqual(0, j.Count);
        }
Exemplo n.º 5
0
        private static JsonArray ParseArray(char[] json, ref int index, ref bool success)
        {
            JsonArray jsonArray = new JsonArray();

            SimpleJsonTool.NextToken(json, ref index);
            bool      flag = false;
            JsonArray result;

            while (!flag)
            {
                int num = SimpleJsonTool.LookAhead(json, index);
                if (num != 0)
                {
                    if (num == 6)
                    {
                        SimpleJsonTool.NextToken(json, ref index);
                    }
                    else
                    {
                        if (num == 4)
                        {
                            SimpleJsonTool.NextToken(json, ref index);
                            break;
                        }
                        object item = SimpleJsonTool.ParseValue(json, ref index, ref success);
                        if (!success)
                        {
                            result = null;
                            return(result);
                        }
                        jsonArray.Add(item);
                    }
                    continue;
                }
                success = false;
                result  = null;
                return(result);
            }
            result = jsonArray;
            return(result);
        }
Exemplo n.º 6
0
        public static JsonArray ReadFrom(JsonTextReader reader)
        {
            if (!reader.IsStartArray)
            {
                throw new FormatException("Error reading JSON array.");
            }

            var array = new JsonArray();

            while (reader.Read())
            {
                if (reader.IsEndArray)
                {
                    return(array);
                }

                array.Add(reader.GetJsonMember());
            }

            throw new FormatException("Unexpected end of the JSON");
        }
Exemplo n.º 7
0
        private static JsonArray ParseArray(char[] json, ref int index, ref bool success)
        {
            JsonArray jsonArray = new JsonArray();

            NextToken(json, ref index);
            bool flag = false;

            while (!flag)
            {
                switch (LookAhead(json, index))
                {
                case 0:
                    success = false;
                    return(null);

                case 6:
                    NextToken(json, ref index);
                    continue;

                case 4:
                    break;

                default:
                {
                    object item = ParseValue(json, ref index, ref success);
                    if (!success)
                    {
                        return(null);
                    }
                    jsonArray.Add(item);
                    continue;
                }
                }
                NextToken(json, ref index);
                break;
            }
            return(jsonArray);
        }
    private void ExportRecordedDataToJSON()
    {
        JsonObject recordedData = new JsonObject();
        JsonArray posRotArray = new JsonArray();

        for( int i = 0; i < recordedPositions.Count; i++ ) {
            // Get reference to current position/rotation in our recorded data
            Vector3 currentPos = recordedPositions[i];
            float currentYRot = recordedYRotations[i];

            // Build out position and rotation objects
            JsonObject posV = new JsonObject();
            posV.Add( "x", currentPos.x );
            posV.Add( "y", currentPos.y );
            posV.Add( "z", currentPos.z );

        //			JsonObject rotQ = new JsonObject();
        //			rotQ.Add( "w", currentYRot.w );
        //			rotQ.Add( "x", currentYRot.x );
        //			rotQ.Add( "y", currentYRot.y );
        //			rotQ.Add( "z", currentYRot.z );

            // Create and populate object that will encapsulate position and rotation at this index
            JsonObject posRotPair = new JsonObject();
            posRotPair.Add( "posV", posV );
            posRotPair.Add( "yRot", currentYRot );

            // Add new object to array of positions
            posRotArray.Add( posRotPair );
        }
        // Add array of positions to recorded data
        recordedData.Add( "frames", posRotArray );

        _Rester.PostJSON( "asaghostmatch.herokuapp.com/data", recordedData, ( string err, JsonObject retJO ) => {
            Debug.Log( err );
        });
        Debug.LogWarning( "Exporting complete." );
    }
Exemplo n.º 9
0
        private static JsonArray ParseArray(char[] json, ref int index, ref bool success)
        {
            JsonArray jsonArray = new JsonArray();

            SimpleJson.NextToken(json, ref index);
            bool flag = false;

            while (!flag)
            {
                int num = SimpleJson.LookAhead(json, index);
                if (num == 0)
                {
                    success = false;
                    return(null);
                }
                if (num == 6)
                {
                    SimpleJson.NextToken(json, ref index);
                }
                else
                {
                    if (num == 4)
                    {
                        SimpleJson.NextToken(json, ref index);
                        break;
                    }
                    object item = SimpleJson.ParseValue(json, ref index, ref success);
                    if (!success)
                    {
                        return(null);
                    }
                    jsonArray.Add(item);
                }
            }
            return(jsonArray);
        }
Exemplo n.º 10
0
        private static JsonArray ParseArray(char[] json, ref int index, ref bool success)
        {
            JsonArray jsonArray = new JsonArray();

            SimpleJson.SimpleJson.NextToken(json, ref index);
            bool flag = false;

            while (!flag)
            {
                switch (SimpleJson.SimpleJson.LookAhead(json, index))
                {
                case 0:
                    success = false;
                    return((JsonArray)null);

                case 6:
                    SimpleJson.SimpleJson.NextToken(json, ref index);
                    continue;

                case 4:
                    SimpleJson.SimpleJson.NextToken(json, ref index);
                    goto label_9;

                default:
                    object obj = SimpleJson.SimpleJson.ParseValue(json, ref index, ref success);
                    if (!success)
                    {
                        return((JsonArray)null);
                    }
                    jsonArray.Add(obj);
                    continue;
                }
            }
label_9:
            return(jsonArray);
        }
Exemplo n.º 11
0
 public override void Add (JsonNode aItem)
 {
     var tmp = new JsonArray();
     tmp.Add(aItem);
     Set(tmp);
 }
Exemplo n.º 12
0
 public override JsonNode this[int aIndex]
 {
     get
     {
         return new JsonLazyCreator(this);
     }
     set
     {
         var tmp = new JsonArray();
         tmp.Add(value);
         Set(tmp);
     }
 }
Exemplo n.º 13
0
        public static JsonNode Deserialize(System.IO.BinaryReader aReader)
        {
            JSONBinaryTag type = (JSONBinaryTag)aReader.ReadByte();
            switch(type)
            {
            case JSONBinaryTag.Array:
            {
                int count = aReader.ReadInt32();
                JsonArray tmp = new JsonArray();
                for(int i = 0; i < count; i++)
                    tmp.Add(Deserialize(aReader));
                return tmp;
            }
            case JSONBinaryTag.Class:
            {
                int count = aReader.ReadInt32();                
                JsonClass tmp = new JsonClass();
                for(int i = 0; i < count; i++)
                {
                    string key = aReader.ReadString();
                    var val = Deserialize(aReader);
                    tmp.Add(key, val);
                }
                return tmp;
            }
            case JSONBinaryTag.Value:
            {
                return new JsonData(aReader.ReadString());
            }
            case JSONBinaryTag.IntValue:
            {
                return new JsonData(aReader.ReadInt32());
            }
            case JSONBinaryTag.DoubleValue:
            {
                return new JsonData(aReader.ReadDouble());
            }
            case JSONBinaryTag.BoolValue:
            {
                return new JsonData(aReader.ReadBoolean());
            }
            case JSONBinaryTag.FloatValue:
            {
                return new JsonData(aReader.ReadSingle());
            }
 
            default:
            {
                throw new Exception("Error deserializing Json. Unknown tag: " + type);
            }
            }
        }
Exemplo n.º 14
0
        public void RemoveAt()
        {
            object v1 = 1;
            object v2 = 2;
            object v3 = 3;

            JsonArray j = new JsonArray();
            j.Add(v1);
            j.Add(v2);
            j.Add(v3);

            Assert.AreEqual(true, j.Contains(v1));
            j.RemoveAt(0);
            Assert.AreEqual(false, j.Contains(v1));

            Assert.AreEqual(true, j.Contains(v3));
            j.RemoveAt(1);
            Assert.AreEqual(false, j.Contains(v3));

            Assert.AreEqual(1, j.Count);
        }
Exemplo n.º 15
0
        public void Item()
        {
            object v1 = 1;
            object v2 = 2;
            object v3 = 3;
            object v4 = 4;

            JsonArray j = new JsonArray();

            j.Add(v1);
            j.Add(v2);
            j.Add(v3);

            j[1] = v4;

            Assert.AreEqual(-1, j.IndexOf(v2));
            Assert.AreEqual(1, j.IndexOf(v4));
        }
Exemplo n.º 16
0
        void TextBlockTips__Changed(object sender, TextChangedEventArgs e)
        {
            //this.ButtonApplyConfig_.IsEnabled = true;

            // Tips
            string[] tips = this.TextBlockTips_.Text.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
            JsonArray tipsArray = new JsonArray();
            foreach (string tip in tips)
            {
                tipsArray.Add(tip);
            }
            Config["Tips"] = tipsArray;

            SaveConfigFile();
        }