|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using System.Globalization;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Converters;
-
- namespace jdis_import.RESTObjects
- {
- [JsonObject(MemberSerialization.OptIn)]
- public class RESTResponse<T>
- {
- #region Fields
-
- private RESTMeta _meta = null;
- private T _data;
-
- #endregion
-
- #region Properties
- [JsonProperty(PropertyName = "meta")]
- public RESTMeta meta
- {
- get
- {
- if (_meta == null)
- {
- _meta = new RESTMeta();
- }
- return _meta;
- }
- set { _meta = value; }
- }
- [JsonProperty(PropertyName = "data")]
- public T data
- {
- get { return _data; }
- set { _data = value; }
- }
-
- #endregion
- }
- public static class Deserialize
- {
- public static T FromJson<T>(string json)
- {
- return JsonConvert.DeserializeObject<T>(json, Converter.Settings);
- }
- }
- public static class Serialize
- {
- public static string ToJson<T>(this T self)
- {
- return JsonConvert.SerializeObject(self, Converter.Settings);
- }
- }
- internal static class Converter
- {
- public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
- {
- MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
- DateParseHandling = DateParseHandling.None,
- DateFormatHandling = DateFormatHandling.MicrosoftDateFormat,
- };
- }
- }
|