是否ServiceStack.Text报价pretty的印刷JSON的?Text、ServiceStack、JSON、pretty

2023-09-04 07:23:38 作者:戒烟戒酒戒撸

TL; DR:是否有一个内置的方式在ServiceStack.Text产生pretty的印刷JSON

TL;DR: Is there a built-in way in ServiceStack.Text to produce pretty-printed JSON?

我使用 ServiceStack.Text 做JSON序列化。它的作品真的很好,到目前为止,但所创建的JSON(使用 .ToJSON())(通过网络发送时,最有可能节省空间)未格式化用空格或换行符。然而,在某些情况下,这将是不错的JSON格式,便于人类可读性。

I am using ServiceStack.Text for doing JSON serialization. It works really good so far, but the created JSON (using .ToJSON()) is not formated with whitespaces or newlines (most likely to save space when sending over the network). However, in some circumstances it would be nice to have the JSON formatted for easier human-readability.

使用.dump()方法做某种格式的,但是不会产生有效的JSON(即周围的双引号缺失)。

The .Dump () method does some sort of formatting, however does not produce valid JSON (i.e. the surrounding doublequotes are missing).

推荐答案

T.Dump() T.PrintDump()扩展在 ServiceStack.Text 的方法仅仅是pretty的格式版本在 JSV格式,它将与该TypeSerializer类或 T.ToJsv()扩展方法。它只是提供数据的对人友好的转储,它不解析的。

The T.Dump() and T.PrintDump() extension methods in ServiceStack.Text are just a pretty formatted version of the JSV Format that's created with the TypeSerializer class or T.ToJsv() Extension method. It is only to provide a human friendly dump of data, it's not parseable.

没有prettyPrint的JSON,我建议安装一个pretty的JSONView扩展Chrome或Firefox,看看pretty的JSON,也可以粘贴在JSON的 JSON prettyprint.com

There is no PrettyPrint for JSON, I recommend installing a Pretty JSONView extension for Chrome or Firefox to see pretty JSON or you can paste the JSON in jsonprettyprint.com

 
精彩推荐
图片推荐