public void ReadJsonUnsupportedValue()
        {
            string json = "undefined";

            JsonTextReader writer = new JsonTextReader(new StringReader(json));

            JsonValueConverter converter = new JsonValueConverter();

            ExceptionAssert.Throws <JsonException>("Unexpected or unsupported token: Undefined. Path '', line 1, position 9.",
                                                   () =>
            {
                converter.ReadJson(writer, typeof(JsonValue), null, null);
            });
        }
示例#2
0
        public void ReadJsonUnexpectedEndInObject()
        {
            string json = "{'hi':";

            JsonTextReader writer = new JsonTextReader(new StringReader(json));

            JsonValueConverter converter = new JsonValueConverter();

            ExceptionAssert.Throws <JsonException>("Unexpected end. Path 'hi', line 1, position 6.",
                                                   () =>
            {
                converter.ReadJson(writer, typeof(JsonValue), null, null);
            });
        }
        public void ReadJsonBadJsonType()
        {
            string json = "null";

            JsonTextReader writer = new JsonTextReader(new StringReader(json));

            JsonValueConverter converter = new JsonValueConverter();

            ExceptionAssert.Throws <JsonException>(() =>
            {
                converter.ReadJson(writer, typeof(JsonObject), null, null);
            },
                                                   "Could not convert 'Windows.Data.Json.JsonValue' to 'Windows.Data.Json.JsonObject'. Path '', line 1, position 4.");
        }
示例#4
0
        public void ReadJsonUnexpectedEndAfterComment()
        {
            string json = "[/*comment!*/";

            JsonTextReader writer = new JsonTextReader(new StringReader(json));

            JsonValueConverter converter = new JsonValueConverter();

            ExceptionAssert.Throws <JsonException>("Unexpected end. Path '', line 1, position 13.",
                                                   () =>
            {
                converter.ReadJson(writer, typeof(JsonValue), null, null);
            });
        }
        public void ReadJson()
        {
            string json = @"{
  ""CPU"": ""Intel"",
  ""Drives"": [
    ""DVD read/writer"",
    ""500 gigabyte hard drive""
  ]
}";

            JsonTextReader writer = new JsonTextReader(new StringReader(json));

            JsonValueConverter converter = new JsonValueConverter();
            JsonObject         o         = (JsonObject)converter.ReadJson(writer, typeof(JsonObject), null, null);

            Assert.AreEqual(2, o.Count);
            Assert.AreEqual("Intel", o.GetNamedString("CPU"));
            Assert.AreEqual("DVD read/writer", o.GetNamedArray("Drives")[0].GetString());
            Assert.AreEqual("500 gigabyte hard drive", o.GetNamedArray("Drives")[1].GetString());
        }