如何将YAML转换为JSON? [英] How to convert YAML to JSON?

查看:1138
本文介绍了如何将YAML转换为JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找在YAML文件和JSON之间进行转换的方法.真的很难找到任何信息.

I'm looking to convert between a YAML file, and JSON. This was really difficult to find any information on.

推荐答案

如果不需要Json.NET的功能,还可以直接使用Serializer类发出JSON:

If you do not need the features of Json.NET, you can also use the Serializer class directly to emit JSON:

// now convert the object to JSON. Simple!
var js = new Serializer(SerializationOptions.JsonCompatible);

var w = new StringWriter();
js.Serialize(w, o);
string jsonText = w.ToString();

您可以在此处检查两个有效的小提琴:

You can check two working fiddles here:

  • Convert YAML to JSON
  • Convert YAML to JSON using Json.NET

这篇关于如何将YAML转换为JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆