如何在没有格式化的情况下序列化 JObject? [英] How to serialize a JObject without the formatting?

查看:22
本文介绍了如何在没有格式化的情况下序列化 JObject?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 LINQ to JSON 构建的 JObject(我正在使用 Json.Net)(也由同一个库提供).当我在 JObject 上调用 ToString() 方法时,它会将结果输出为格式化的 JSON.

I have a JObject (I'm using Json.Net) that I constructed with LINQ to JSON (also provided by the same library). When I call the ToString() method on the JObject, it outputs the results as formatted JSON.

如何将格式设置为无"?

How do I set the formatting to "none" for this?

推荐答案

调用JObject的ToString(Formatting.None)方法.

Call JObject's ToString(Formatting.None) method.

或者,如果您将对象传递给 JsonConvert.SerializeObject 方法,它将返回不带格式的 JSON.

Alternatively if you pass the object to the JsonConvert.SerializeObject method it will return the JSON without formatting.

文档:使用 JToken.ToString 编写 JSON 文本

这篇关于如何在没有格式化的情况下序列化 JObject?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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