本文整理汇总了C#中JValue.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# JValue.ToString方法的具体用法?C# JValue.ToString怎么用?C# JValue.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JValue
的用法示例。
在下文中一共展示了JValue.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToStringFormat
public void ToStringFormat()
{
JValue v = new JValue(new DateTime(2013, 02, 01, 01, 02, 03, 04));
Assert.Equal("2013", v.ToString("yyyy"));
}
示例2: ToString
public void ToString()
{
JValue v;
v = new JValue(true);
Assert.AreEqual("True", v.ToString());
v = new JValue(Encoding.UTF8.GetBytes("Blah"));
Assert.AreEqual("System.Byte[]", v.ToString(null, CultureInfo.InvariantCulture));
v = new JValue("I am a string!");
Assert.AreEqual("I am a string!", v.ToString());
v = new JValue(null, JTokenType.Null);
Assert.AreEqual("", v.ToString());
v = new JValue(null, JTokenType.Null);
Assert.AreEqual("", v.ToString(null, CultureInfo.InvariantCulture));
v = new JValue(new DateTime(2000, 12, 12, 20, 59, 59, DateTimeKind.Utc), JTokenType.Date);
Assert.AreEqual("12/12/2000 20:59:59", v.ToString(null, CultureInfo.InvariantCulture));
v = new JValue(new Uri("http://json.codeplex.com/"));
Assert.AreEqual("http://json.codeplex.com/", v.ToString(null, CultureInfo.InvariantCulture));
v = new JValue(TimeSpan.FromDays(1));
Assert.AreEqual("1.00:00:00", v.ToString(null, CultureInfo.InvariantCulture));
v = new JValue(new Guid("B282ADE7-C520-496C-A448-4084F6803DE5"));
Assert.AreEqual("b282ade7-c520-496c-a448-4084f6803de5", v.ToString(null, CultureInfo.InvariantCulture));
}
示例3: WriteSingle
public void WriteSingle()
{
float f = 5.2f;
JValue value = new JValue(f);
string json = value.ToString(Formatting.None);
Assert.Equal("5.2", json);
}