How to serialize a JObject without the formatting?

后端 未结 3 972
灰色年华
灰色年华 2020-12-24 04:01

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

相关标签:
3条回答
  • 2020-12-24 04:46

    You can also do the following;

    string json = myJObject.ToString(Newtonsoft.Json.Formatting.None);
    
    0 讨论(0)
  • 2020-12-24 04:48

    you can use JsonConvert.SerializeObject()

    JsonConvert.SerializeObject(myObject) // myObject is returned by JObject.Parse() method
    

    JsonConvert.SerializeObject()

    JObject.Parse()

    0 讨论(0)
  • 2020-12-24 04:59

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

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

    Documentation: Write JSON text with JToken.ToString

    0 讨论(0)
提交回复
热议问题