Replacement for JDIS Importer
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

66 строки
1.6 KiB

  1. using System.Globalization;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Converters;
  4. using System;
  5. namespace jdis_import.RESTObjects
  6. {
  7. [JsonObject(MemberSerialization.OptIn)]
  8. public class RESTResponse<T>
  9. {
  10. #region Fields
  11. private RESTMeta _meta = null;
  12. private T _data;
  13. #endregion
  14. #region Properties
  15. [JsonProperty(PropertyName = "meta")]
  16. public RESTMeta meta
  17. {
  18. get
  19. {
  20. if (_meta == null)
  21. {
  22. _meta = new RESTMeta();
  23. }
  24. return _meta;
  25. }
  26. set { _meta = value; }
  27. }
  28. [JsonProperty(PropertyName = "data")]
  29. public T data
  30. {
  31. get { return _data; }
  32. set { _data = value; }
  33. }
  34. #endregion
  35. }
  36. public static class Deserialize
  37. {
  38. public static T FromJson<T>(string json)
  39. {
  40. //Console.WriteLine(json);
  41. return JsonConvert.DeserializeObject<T>(json, Converter.Settings);
  42. }
  43. }
  44. public static class Serialize
  45. {
  46. public static string ToJson<T>(this T self)
  47. {
  48. return JsonConvert.SerializeObject(self, Converter.Settings);
  49. }
  50. }
  51. internal static class Converter
  52. {
  53. public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
  54. {
  55. MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
  56. DateParseHandling = DateParseHandling.None,
  57. DateFormatHandling = DateFormatHandling.MicrosoftDateFormat,
  58. };
  59. }
  60. }