コード例 #1
0
        public void DeserializeSurrogatePair()
        {
            string json = "{\"t\":\"𩸽 is Arabesque greenling(fish) in japanese\"}";
            var    p    = PixelJSON.LoadString(json);

            Assert.AreEqual("𩸽 is Arabesque greenling(fish) in japanese", p["t"]);
        }
コード例 #2
0
        public void DeserializeDoubleQuotesCorrectly()
        {
            var json = "{\"message\":\"Hi \\\"Prabir\\\"\"}";
            var p    = PixelJSON.LoadString(json);

            Assert.AreEqual("Hi \"Prabir\"", p["message"]);
        }
コード例 #3
0
        public void DeserializeUriCorrectly()
        {
            var json = "{\"url\":\"https://github.com/shiftkey/simple-json/issues/1\"}";
            var p    = PixelJSON.LoadString(json);

            Assert.AreEqual(new Uri("https://github.com/shiftkey/simple-json/issues/1"), p["url"]);
        }
コード例 #4
0
        public void DeserializeUnicodeChar()
        {
            string json = "{\"t\" : \"न\"}";

            var p = PixelJSON.LoadString(json);

            Assert.AreEqual("न", p["t"]);
        }
コード例 #5
0
        public void ReadUnicode()
        {
            string json = @"{""Message"":""Hi,I\u0092ve send you smth""}";

            var p = PixelJSON.LoadString(json);

            Assert.AreEqual(@"Hi,I" + '\u0092' + "ve send you smth", p["Message"]);
        }
コード例 #6
0
        public void RootWithArray()
        {
            var json = "[45,56,787,3]";
            var p    = PixelJSON.LoadString(json);

            Assert.AreEqual("56", p.array[1]);
            Assert.AreEqual("787", p.array[2]);
        }
コード例 #7
0
        public void RootWithArrayofObjects()
        {
            var json = "[{\"cans\":10},{\"gum\":bubble}]";
            var p    = PixelJSON.LoadString(json);

            Assert.AreEqual("10", p[0, "cans"]);
            Assert.AreEqual("bubble", p[1, "gum"]);
        }
コード例 #8
0
        public void InvalidJSON()
        {
            var p = PixelJSON.LoadString("hi");

            Assert.IsNull(p.table);
            Assert.IsNull(p.array);
            Assert.IsNull(p["stuff"]);
        }
コード例 #9
0
        public void DeserializeInvaildEscapedSurrogatePair()
        {
            string json = "\"\\uD867\\u0000 is Arabesque greenling(fish)\"";
            var    p    = PixelJSON.LoadString(json);

            Assert.IsNull(p.array);
            Assert.IsNull(p.table);
        }
コード例 #10
0
        public void DeserializeEscapedSurrogatePair()
        {
            string json = "{\"t\":\"\\uD867\\uDE3D is Arabesque greenling(fish)\"}";  // 𩸽
            var    p    = PixelJSON.LoadString(json);

            Assert.AreEqual("\uD867\uDE3D is Arabesque greenling(fish)", p["t"]);
            Assert.AreEqual("𩸽 is Arabesque greenling(fish)", p["t"]);
        }
コード例 #11
0
        public void ParseIncompleteArray()
        {
            var p = PixelJSON.LoadString("[1");

            //Assert.IsNotNull(p.array);
            //Assert.AreEqual(1, p.array.Length);
            Assert.IsNull(p.array);
            Assert.IsNull(p.table);
        }
コード例 #12
0
        public void UnexpectedEndWhenParsingUnquotedProperty()
        {
            var p = PixelJSON.LoadString(@"{aww");

            //The array object should be null
            Assert.IsNull(p.array);

            Assert.IsNotNull(p.table);
            Assert.AreEqual(0, p.table.Count);
        }
コード例 #13
0
        public void ReadEmptyObject()
        {
            var p = PixelJSON.LoadString("{}");

            //The array object should be null
            Assert.IsNull(p.array);

            Assert.IsNotNull(p.table);

            Assert.AreEqual(0, p.table.Count);
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: bncastle/PixelJSON
        static void Main(string[] args)
        {
            var z = new object[] { "straight", "royal" };
            var s = z.ToArray <string>();
            //var p = PJSON.LoadString("{\"Tst\": 1.03e4 \"night\":9,\"Lost Weight\": [true,false,true,true] , \"Tap\":{\"Filer\":90} } ");
            //var p = PJSON.LoadString("[{\"firstName\":\"John\", \"lastName\":\"Doe\"},{\"firstName\":\"Anna\", \"lastName\":\"Smith\"},{\"firstName\":\"Peter\",\"lastName\":\"Jones\"}]");
            //var p = PJSON.LoadString("[45,67,34,21,32,1]");

            //var p = PixelJSON.Load(@"F:\untitled.json");
            //string json = @"{ ""t"" : ""'h\u006""}";
            //string json = @"{ ""A"" : true,""B"" ""hello"", // Notice the colon is missing""C"" : ""bye""}";
            //string json = "[1";
            string json = @"{
  ""CPU"": ""Intel"",
  ""Drives"": [
    ""DVD read/writer"",
    ""500 gigabyte hard drive""
  ],
   ""Old"" : {""Bat"" : ""Masterson""}
}";
            var    p    = PixelJSON.LoadString(json);

            var str = PixelJSONSerializer.Serialize(p, true, false);

            Console.WriteLine(str);
            //var p = JSONer.LoadString(@"{""t"" : ""'h\""}");
            //var p = JSON.LoadString(@"{aww");
            //string json = @"[""\u003c"",""\u5f20""]";
            //var p = PJSON.LoadString(json);
            //Is our root item an object?
            //if (p.table != null)
            //{
            //    Console.WriteLine(p["height"]);
            //}
            //else //Or is it an array?
            //{
            //    Console.WriteLine(p[0, "firstName"]);
            //    Console.WriteLine(p[0, "lastName"]);
            //}

            //Test serializer
            //using (var sw = new StreamWriter(@"F:\out.txt"))
            //{
            //    sw.WriteLine(PixelJSONSerializer.Serialize(p,true));
            //}

            //Console.WriteLine(p.root.ToArray<int>()[0]);
            //Console.WriteLine(p.root[0]["firstName"].value);
            //	Console.WriteLine (p.main["Tst"].value);
            //	Console.WriteLine (p.main["night"].value);
            //	Console.WriteLine (p.main["Lost Weight"].ArrB());
            //	Console.WriteLine (p.main["Tap"].obj["Filer"].value);
        }
コード例 #15
0
        public void UnexpectedEndOfControlCharacter()
        {
            var p = PixelJSON.LoadString(@"{""t"" : ""'h\""}");

            //The array object should be null
            Assert.IsNull(p.array);

            Assert.IsNotNull(p.table);

            Assert.AreEqual("'h\"}", p["t"]);

            Assert.AreEqual(1, p.table.Count);
        }
コード例 #16
0
        public void MissingColon()
        {
            string json = @"{
    ""A"" : true,
    ""B"" ""hello"", // Notice the colon is missing
    ""C"" : ""bye""
}";

            var p = PixelJSON.LoadString(json);

            Assert.IsNull(p.array);
            Assert.IsNull(p.table);
        }
コード例 #17
0
        public void NestedObjects()
        {
            string input = @"{
  ""CPU"": ""Intel"",
  ""Drives"": [
    ""DVD read/writer"",
    ""500 gigabyte hard drive""
  ],
   ""Old"" : {""Bat"" : ""Masterson""}
}";
            var    p     = PixelJSON.LoadString(input);

            Assert.AreEqual("Masterson", p["Old", "Bat"]);
        }
コード例 #18
0
        public void UnexpectedEndOfHex()
        {
            //For a short hex code, we dont throw an exception
            //we just skip it. TODO: Might change behavior if I use this for anything other than Unity3d stuff.
            var p = PixelJSON.LoadString(@"{ ""t"" : ""'h\u006""}");

            //The array object should be null
            Assert.IsNull(p.array);

            Assert.IsNotNull(p.table);

            Assert.AreEqual("'h", p["t"]);

            Assert.AreEqual(1, p.table.Count);
        }
コード例 #19
0
        public void LongStringTests()
        {
            int    length = 20000;
            string json   = @"[""" + new string(' ', length) + @"""]";

            var p = PixelJSON.LoadString(json);

            Assert.IsNotNull(p.array);

            Assert.IsNull(p.table);

            Assert.IsInstanceOfType(p.StringFromArray(0), typeof(string));

            Assert.AreEqual(20000, (p.StringFromArray(0)).Length);
        }
コード例 #20
0
        public void EscapedUnicodeTests()
        {
            string json = @"[""\u003c"",""\u5f20""]";

            var p = PixelJSON.LoadString(json);

            Assert.IsNotNull(p.array);

            Assert.IsNull(p.table);

            Assert.AreEqual(2, p.array.Length);

            Assert.AreEqual("<", p.StringFromArray(0));
            //Assert.AreEqual("24352", Convert.ToInt32(Convert.ToChar(l[0])));
        }
コード例 #21
0
        public void ParsingQuotedPropertyWithControlCharacters()
        {
            var p = PixelJSON.LoadString("{\"hi\r\nbye\":1}");

            //The array object should be null
            Assert.IsNull(p.array);

            Assert.IsNotNull(p.table);
            Assert.AreEqual(1, p.table.Count);

            foreach (KeyValuePair <string, object> pair in p.table)
            {
                Assert.AreEqual(@"hi
bye", pair.Key);
            }
        }
コード例 #22
0
        public void ReadNewLineLastCharacter()
        {
            string input = @"{
  ""CPU"": ""Intel"",
  ""Drives"": [ 
    ""DVD read/writer"",
    ""500 gigabyte hard drive""
  ]
}" + '\n';

            var p = PixelJSON.LoadString(input);

            //The array object should be null
            Assert.IsNull(p.array);

            Assert.IsNotNull(p.table);
            Assert.AreEqual(2, p.table.Count);

            Assert.AreEqual("Intel", p["CPU"]);
        }
コード例 #23
0
        public void ReadIndented()
        {
            string input = @"{
  ""CPU"": ""Intel"",
  ""Drives"": [
    ""DVD read/writer"",
    ""500 gigabyte hard drive""
  ]
}";
            var    p     = PixelJSON.LoadString(input);

            //The array object should be null
            Assert.IsNull(p.array);

            Assert.AreEqual("Intel", p["CPU"]);
            Assert.IsInstanceOfType(p.table["Drives"], typeof(object[]));

            //Check count
            Assert.AreEqual(2, ((object[])p.table["Drives"]).Length);

            //Check data
            Assert.AreEqual("DVD read/writer", p["Drives", 0]);
            Assert.AreEqual("500 gigabyte hard drive", p["Drives", 1]);
        }
コード例 #24
0
        public void ReadNullTerminatedString()
        {
            var p = PixelJSON.LoadString("{\"Nuller\":\"h\0i\"}");

            Assert.AreEqual("h\0i", p["Nuller"]);
        }