如何使用MVC4API获得以下JSON响应以使其看起来更清晰。这是一个样例JSON
{"Name":"Apple","Expiry":"2008-12-28T00:00:00","Price":3.99}漂亮的JSON
{
"Name":"Apple",
"Expiry":"2008-12-28T00:00:00",
"Price":3.99
}发布于 2015-04-07 18:27:51
如果您使用的是Web Api。您可以设置:
var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
json.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;发布于 2012-10-22 01:49:55
您可以使用Json.net NuGet包完成此操作:
JObject.Parse(json).ToString(Formatting.Indented)发布于 2014-10-28 17:45:18
如果是要序列化到JSON中的对象,只需添加一个参数来“美化”它即可。
JsonConvert.SerializeObject(object, Formatting.Indented);https://stackoverflow.com/questions/12999467
复制相似问题