如何使用Json.net写JSON的时候打开缺口? [英] How to turn on indentation when writing JSON using Json.net?

查看:106
本文介绍了如何使用Json.net写JSON的时候打开缺口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Json.Net序列化XML到JSON。当我序列化的字符串写入一个文件这一切都在一个单一的线。我如何得到它实际上看起来像的Json与通常的标签和缩进?

I am using Json.Net to serialize XML into Json . When i write the serialized string to a file it all comes in a single line . How do i get it to actually look like Json with the usual tabs and indentation?

推荐答案

设置JSON作家<一个href=\"http://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_Formatting.htm\"><$c$c>Formatting属性 Formatting.Indented

jsonWriter.Formatting = Formatting.Indented;

的<一个href=\"http://james.newtonking.com/projects/json/help/html/T_Newtonsoft_Json_JsonConvert.htm\"><$c$c>JsonConvert.Serialize*方法也有采取重载一个格式枚举(感谢约翰平整度)。

The JsonConvert.Serialize* methods also have overloads that take a Formatting enum (thanks John Flatness).

文档: 将对象序列化

这篇关于如何使用Json.net写JSON的时候打开缺口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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