JsonHelper.cs 786 B

123456789101112131415161718192021222324
  1. using System;
  2. namespace ET
  3. {
  4. public static class JsonHelper
  5. {
  6. private static readonly MongoDB.Bson.IO.JsonWriterSettings logDefineSettings = new MongoDB.Bson.IO.JsonWriterSettings() { OutputMode = MongoDB.Bson.IO.JsonOutputMode.RelaxedExtendedJson };
  7. public static string ToJson(object message)
  8. {
  9. return MongoDB.Bson.BsonExtensionMethods.ToJson(message, logDefineSettings);
  10. }
  11. public static object FromJson(Type type, string json)
  12. {
  13. return MongoDB.Bson.Serialization.BsonSerializer.Deserialize(json, type);
  14. }
  15. public static T FromJson<T>(string json)
  16. {
  17. return MongoDB.Bson.Serialization.BsonSerializer.Deserialize<T>(json);
  18. }
  19. }
  20. }