BimJsonUtil.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. jsetting.Converters.Add(new XYZConverter());
  24. jsetting.Converters.Add(new StringEnumConverter());
  25. //var serializer = JsonSerializer.Create(jsetting);
  26. //JObject jobject = new JObject();
  27. //foreach (var collection in m_DataSource)
  28. //{
  29. // jobject.Add(collection.Key, JArray.FromObject(collection.Value, serializer));
  30. //}
  31. //var settings = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore };
  32. string dataStr = JsonConvert.SerializeObject(document.BimObjects, jsetting);
  33. return dataStr;
  34. }
  35. }
  36. }