当前位置: 首页>>代码示例>>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;未经允许,请勿转载。