本文整理汇总了C#中Book.ToJson方法的典型用法代码示例。如果您正苦于以下问题:C# Book.ToJson方法的具体用法?C# Book.ToJson怎么用?C# Book.ToJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Book
的用法示例。
在下文中一共展示了Book.ToJson方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Objects_Do_Not_Survive_RoundTrips_Via_StringStringDictionary_Due_To_DoubleQuoted_Properties
public void Objects_Do_Not_Survive_RoundTrips_Via_StringStringDictionary_Due_To_DoubleQuoted_Properties()
{
var book = new Book();
book.Id = 1234;
book.Title = "ServiceStack in Action";
book.CategoryId = 16;
book.Description = "Manning eBooks";
var json = book.ToJson();
Console.WriteLine("Book to Json: " + json);
var dictionary = json.FromJson<Dictionary<string, string>>();
Console.WriteLine("Json to Dictionary: " + dictionary.Dump());
var fromDictionary = dictionary.ToJson();
Console.WriteLine("Json from Dictionary: " + fromDictionary);
var fromJsonViaDictionary = fromDictionary.FromJson<Book>();
Assert.AreEqual(book.Description, fromJsonViaDictionary.Description);
Assert.AreEqual(book.Id, fromJsonViaDictionary.Id);
Assert.AreEqual(book.Title, fromJsonViaDictionary.Title);
Assert.AreEqual(book.CategoryId, fromJsonViaDictionary.CategoryId);
}