Exemplo n.º 1
0
        public void UnicodeText()
        {
            // see https://www.dropbox.com/developers/reference/json-encoding
            string   text     = "\"some_üñîcødé_and_\x7f\"";
            JsonText jsonText = JsonText.Parse(text);

            Assert.AreEqual(@"some_\u00fc\u00f1\u00eec\u00f8d\u00e9_and_\u007f", jsonText.Value);
            Assert.AreEqual(text.Trim('\"'), jsonText.FromJson <string>());
            text     = "\"Welcome 🤗 to a link🔗\"";
            jsonText = JsonText.Parse(text);
            Assert.AreEqual(@"Welcome \ud83e\udd17 to a link\ud83d\udd17", jsonText.Value);
            Assert.AreEqual(text.Trim('\"'), jsonText.FromJson <string>());
            text     = "\"More than\rone line.\nThree in fact!\r\nNo four :-)\"";
            jsonText = JsonText.Parse(text);
            Assert.AreEqual(@"More than\u000done line.\u000aThree in fact!\u000d\u000aNo four :-)", jsonText.Value);
            Assert.AreEqual(text.Trim('\"'), jsonText.FromJson <string>());
        }
Exemplo n.º 2
0
        public void ParseLiteral()
        {
            Assert.IsFalse(JsonBool.Parse("false").Value);
            Assert.IsTrue(JsonBool.Parse("true").Value);
            Assert.AreEqual("false", new JsonBool(false).ToString());
            Assert.AreEqual("true", new JsonBool(true).ToString());
            Assert.AreEqual("id", JsonText.Parse("\"id\"").Value);
            Assert.AreEqual(89, JsonNumber.Parse("89").Byte);
            Assert.AreEqual("\"{<guid>}\"", JsonText.Parse("\"\\\"{<guid>}\\\"\"").Value);
            Assert.AreEqual(-0.5m, JsonNumber.Parse("-0.5").Decimal);
            Assert.AreEqual(500d, JsonNumber.Parse("+0.5E3").Double);
            Assert.AreEqual(0.0005d, JsonNumber.Parse("0.5E-3").Double);
            JsonObject   o    = new JsonObject(("name", new JsonText("Lars \"kodekarl\" Hammer")));
            const string json = "{\"name\":\"Lars \\\"kodekarl\\\" Hammer\"}";

            Assert.AreEqual(json, o.ToString());
            Assert.AreEqual(json, JsonValue.Parse(json).ToString());
            Assert.AreEqual(json, JsonValue.Parse(o.Format()).ToString());
        }