本文整理汇总了C#中Person.ToJson方法的典型用法代码示例。如果您正苦于以下问题:C# Person.ToJson方法的具体用法?C# Person.ToJson怎么用?C# Person.ToJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Person
的用法示例。
在下文中一共展示了Person.ToJson方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestStringWithSpecialCharactersRoundTrip
public void TestStringWithSpecialCharactersRoundTrip()
{
Person person = new Person { Name = "Slash \\, Quote \", NewLine \n, Single Quote '" };
string json = person.ToJson();
var person2 = json.ParseJson<Person>();
person2.Name.ShouldBe(person.Name);
}
示例2: DeserializePoco_FromJson
public void DeserializePoco_FromJson()
{
var poco = new Person {Name = "bob"};
var json = poco.ToJson();
var deserialized = BsonSerializer.Deserialize<BsonDocument>(json);
Expect(deserialized["Name"], Is.EqualTo(new BsonString("bob")));
}
示例3: TestPersonWhateverNotNull
public void TestPersonWhateverNotNull()
{
var p = new Person() { Whatever = new Whatever() };
var json = p.ToJson();
var expected = "{ 'Whatever' : { '_t' : 'Whatever' } }".Replace("'", "\"");
Assert.AreEqual(expected, json);
var r = BsonSerializer.Deserialize<Person>(json);
Assert.IsInstanceOf<Whatever>(r.Whatever);
}
示例4: TestPersonWhateverNull
public void TestPersonWhateverNull()
{
var p = new Person();
var json = p.ToJson();
var expected = "{ 'Whatever' : null }".Replace("'", "\"");
Assert.AreEqual(expected, json);
var r = BsonSerializer.Deserialize<Person>(json);
Assert.AreEqual(null, r.Whatever);
}
示例5: Save
public void Save(Person person)
{
var client = new RedisClient();
var key = new PeopleKeys ().GetPersonKey (person.Id);
var json = person.ToJson ();
client.Set(key, json);
var idManager = new DataIdManager ();
idManager.Add (person);
}
示例6: Automatic
public void Automatic()
{
var person = new Person
{
Age = 54,
FirstName = "bob"
};
person.Address.Add("101 Some Road");
person.Address.Add("Unit 501");
person.Contact.Email = "[email protected]";
person.Contact.Phone = "123-456-7908";
Console.WriteLine(person.ToJson());
}
示例7: SerializationAttributes
public void SerializationAttributes()
{
var person = new Person();
Console.WriteLine(person.ToJson());
}