本文整理汇总了C#中JsonSerializer.SerializeToString方法的典型用法代码示例。如果您正苦于以下问题:C# JsonSerializer.SerializeToString方法的具体用法?C# JsonSerializer.SerializeToString怎么用?C# JsonSerializer.SerializeToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonSerializer
的用法示例。
在下文中一共展示了JsonSerializer.SerializeToString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_serialize_and_deserialize_text_email
public void Can_serialize_and_deserialize_text_email()
{
var serializer = new JsonSerializer<EmailMessage>();
var email = MessageFactory.EmailWithText(1).Single();
var json = serializer.SerializeToString(email);
Assert.IsNotNull(json);
Console.WriteLine(json);
var deserialized = serializer.DeserializeFromString(json);
Assert.IsNotNull(deserialized);
}
示例2: Main
static void Main(string[] args)
{
var violations = 0;
const int count = 1000 * 1000;
var json = new List<string>();
var serializer = new JsonSerializer<T>();
for (int i = 0; i < count; i++)
{
var t = new T
{
X = Guid.NewGuid(),
Y = i % 2 == 0 ? 'C' : 'P',
};
json.Add(serializer.SerializeToString(t));
}
var tasks = new List<Task>();
var tasksCount = args.Length > 0 ? int.Parse(args[0]) : 3;
for (int jj = 0; jj < tasksCount; jj++)
{
int j = jj;
tasks.Add(Task.Run(() => {
for (int i = 0; i < count; i++)
{
string s = json[i];
var t = serializer.DeserializeFromString(s);
if (t.Y != (i % 2 == 0 ? 'C' : 'P'))
{
violations++;
Console.WriteLine("Constraint violation index {0} thread {1} expected: {2} received: {3} json: {4}",
i, j, i % 2 == 0 ? 'C' : 'P', t.Y, s);
}
}
}));
}
tasks.ForEach(task => task.Wait());
Console.WriteLine($"There were {violations} viloations, running {tasksCount} Tasks");
}
示例3: test_rect_different_cultures
public void test_rect_different_cultures(string culture)
{
var currentCulture = CultureInfo.GetCultureInfo(culture);
Thread.CurrentThread.CurrentCulture = currentCulture;
Thread.CurrentThread.CurrentUICulture = currentCulture;
var s = new JsonSerializer<Rect>();
var r = new Rect(23, 34, 1024, 768);
var interim = s.SerializeToString(r);
var r2 = s.DeserializeFromString(interim);
Assert.AreEqual(r, r2);
}
示例4: PersonGenerator
static PersonGenerator()
{
_names = File.ReadAllText("names.json").FromJson<Names>();
var serializer = new JsonSerializer<Person>();
_emptySize = serializer.SerializeToString(new Person()).Length;
}
示例5: CacheCurrentTask
protected void CacheCurrentTask()
{
if (LocalCachingEnabled)
{
var serializer = new JsonSerializer<TaskMessage>();
File.WriteAllText(Settings.Default.LocalCache, serializer.SerializeToString(CurrentTask));
}
}