我正在尝试使用 C# 应用程序将 yaml 文件转换为 json 文件。我的应用程序在下一行崩溃了
"created: !ruby/object:ActiveSupport::TimeWithZone"
如何转换日期,因为我需要这部分:“2016-10-14 04:56:51.057147000 Z”
yaml:
- id: 1
created: !ruby/object:ActiveSupport::TimeWithZone
utc: &4 2016-10-14 04:56:51.057147000 Z
zone: *2
time: *4
代码:
using System.IO;
using System;
using YamlDotNet.Serialization;
public class Program
{
public static void Main()
{
var r = new StringReader(@"
- id: 1
created: !ruby/object:ActiveSupport::TimeWithZone
utc: &4 2016-10-14 04:56:51.057147000 Z
zone: *2
time: *4
");
var deserializer = new Deserializer();
var yamlObject = deserializer.Deserialize(r);
var serializer = new Serializer(SerializationOptions.JsonCompatible);
serializer.Serialize(Console.Out, yamlObject);
}
}