當前位置: 首頁>>代碼示例>>C#>>正文


C# Converters.JsonValueConverter類代碼示例

本文整理匯總了C#中Newtonsoft.Json.Converters.JsonValueConverter的典型用法代碼示例。如果您正苦於以下問題:C# JsonValueConverter類的具體用法?C# JsonValueConverter怎麽用?C# JsonValueConverter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JsonValueConverter類屬於Newtonsoft.Json.Converters命名空間,在下文中一共展示了JsonValueConverter類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: WriteJson

    public void WriteJson()
    {
      JsonObject o = JsonObject.Parse(@"{
  ""CPU"": ""Intel"",
  ""Drives"": [
    ""DVD read/writer"",
    ""500 gigabyte hard drive""
  ]
}");

      StringWriter sw = new StringWriter();
      JsonTextWriter writer = new JsonTextWriter(sw);

      JsonValueConverter converter = new JsonValueConverter();
      converter.WriteJson(writer, o, null);

      string json = sw.ToString();

      Assert.AreEqual(@"{""Drives"":[""DVD read/writer"",""500 gigabyte hard drive""],""CPU"":""Intel""}", json);
    }
開發者ID:PrototypeAlpha,項目名稱:LiveSplit,代碼行數:20,代碼來源:JsonValueConverterTests.cs

示例2: ReadJson

    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());
    }
開發者ID:JeffreyZksun,項目名稱:Newtonsoft.Json,代碼行數:20,代碼來源:JsonValueConverterTests.cs

示例3: ReadJsonBadJsonType

    public void ReadJsonBadJsonType()
    {
      string json = "null";

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

      JsonValueConverter converter = new JsonValueConverter();

      ExceptionAssert.Throws<JsonException>("Could not convert 'Windows.Data.Json.JsonValue' to 'Windows.Data.Json.JsonObject'. Path '', line 1, position 4.",
      () =>
      {
        converter.ReadJson(writer, typeof(JsonObject), null, null);
      });
    }
開發者ID:PrototypeAlpha,項目名稱:LiveSplit,代碼行數:14,代碼來源:JsonValueConverterTests.cs

示例4: ReadJsonUnexpectedEndInObject

    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);
      });
    }
開發者ID:PrototypeAlpha,項目名稱:LiveSplit,代碼行數:14,代碼來源:JsonValueConverterTests.cs

示例5: ReadJsonUnexpectedEndAfterComment

    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);
      });
    }
開發者ID:PrototypeAlpha,項目名稱:LiveSplit,代碼行數:14,代碼來源:JsonValueConverterTests.cs

示例6: ReadJsonUnsupportedValue

    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);
      });
    }
開發者ID:PrototypeAlpha,項目名稱:LiveSplit,代碼行數:14,代碼來源:JsonValueConverterTests.cs

示例7: ReadJsonNullValue

    public void ReadJsonNullValue()
    {
      string json = "null";

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

      JsonValueConverter converter = new JsonValueConverter();
      JsonValue v = (JsonValue)converter.ReadJson(writer, typeof(JsonValue), null, null);

      Assert.AreEqual(JsonValueType.Null, v.ValueType);
    }
開發者ID:PrototypeAlpha,項目名稱:LiveSplit,代碼行數:11,代碼來源:JsonValueConverterTests.cs

示例8: ReadJsonUnexpectedEndInArray

        public void ReadJsonUnexpectedEndInArray()
        {
            string json = "[";

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

            JsonValueConverter converter = new JsonValueConverter();

            ExceptionAssert.Throws<JsonException>(() =>
            {
                converter.ReadJson(writer, typeof (JsonValue), null, null);
            }, "Unexpected end. Path '', line 1, position 1.");
        }
開發者ID:j2jensen,項目名稱:ravendb,代碼行數:13,代碼來源:JsonValueConverterTests.cs


注:本文中的Newtonsoft.Json.Converters.JsonValueConverter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。