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

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

问题描述

我有一个JObject(我正在使用Json.Net),它是使用LINQ to JSON(也由同一库提供)构造的.当我在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天全站免登陆