BimJsonUtil.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:BimJsonUtil
  3. * 作者:xulisong
  4. * 创建时间: 2019/6/18 11:23:16
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using JBIM;
  13. using Newtonsoft.Json;
  14. using Newtonsoft.Json.Converters;
  15. using Newtonsoft.Json.Linq;
  16. using RevitToJBim.MBI;
  17. namespace RevitToJBim.JsonConverter
  18. {
  19. public static class BimJsonUtil
  20. {
  21. public static string Serializer(MBIDocument document)
  22. {
  23. JsonSerializerSettings jsetting = CreateDefaultSettings();
  24. string dataStr =JsonConvert.SerializeObject(document, jsetting);
  25. return dataStr;
  26. }
  27. private static JsonSerializerSettings CreateDefaultSettings()
  28. {
  29. JsonSerializerSettings jsetting = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore };
  30. jsetting.Converters.Add(new BimIdConverter());
  31. //mxg 显示x:,y:,z:格式的
  32. //jsetting.Converters.Add(new XYZConverter());
  33. jsetting.Converters.Add(new StringEnumConverter());
  34. jsetting.Converters.Add(new ParameterConverter());
  35. return jsetting;
  36. }
  37. }
  38. }