BimJsonUtil.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. namespace RevitToJBim.JsonConverter
  16. {
  17. public static class BimJsonUtil
  18. {
  19. public static string Serializer(BimDocument document)
  20. {
  21. JsonSerializerSettings jsetting = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore };
  22. jsetting.Converters.Add(new BimIdConverter());
  23. //mxg 显示x:,y:,z:格式的
  24. //jsetting.Converters.Add(new XYZConverter());
  25. jsetting.Converters.Add(new StringEnumConverter());
  26. jsetting.Converters.Add(new ParameterConverter());
  27. //var serializer = JsonSerializer.Create(jsetting);
  28. //JObject jobject = new JObject();
  29. //foreach (var collection in m_DataSource)
  30. //{
  31. // jobject.Add(collection.Key, JArray.FromObject(collection.Value, serializer));
  32. //}
  33. //var settings = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore };
  34. string dataStr = JsonConvert.SerializeObject(document.BimObjects, jsetting);
  35. return dataStr;
  36. }
  37. }
  38. }