/// <summary> /// JSON反序列化 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="restService"></param> /// <param name="jsonContent"></param> /// <returns></returns> public static T Deserialize<T>(this RestServiceBase restService, string jsonContent) { return JsonUtils.DeserializeObject<T>(jsonContent); }
/// <summary> /// REST响应 JSON反序列化 /// </summary> /// <param name="restService"></param> /// <param name="jsonContent"></param> /// <returns></returns> public static ResponseContent DeserializeResponse(this RestServiceBase restService, string jsonContent) { return JsonUtils.DeserializeObject<ResponseContent>(jsonContent); }
/// <summary> /// JSON反序列化(反序列化包含属性Data的JSON字符串,其中Data数据内容派生自ParamsDataBase) /// <example> /// 对如下类对象进行反序列化 /// public sealed class SettingModel : SettingModelBase /// { /// public IJsonContent Data { get; set; } /// } /// 这里Content是接口,在反序列化时需要具体化类型. /// 主要是在Rest Client中处理响应时需要用到 /// </example> /// </summary> /// <param name="restService"></param> /// <typeparam name="TSubElement">JSON模型子内容,其以接口类型实现,需要根据类型具体化</typeparam> /// <param name="jsonContent"></param> /// <returns></returns> public static MultifunctionalContent DeserializeContent<TSubElement>(this RestServiceBase restService, string jsonContent) where TSubElement : class,IJsonContent { var model = JsonUtils.DeserializeObject<MultifunctionalContent, TSubElement>(jsonContent, JsonPropertyFilterEnum.SettingModelData); if (model != null) return model; return null; }
/// <summary> /// REST响应 JSON反序列化 /// <example> /// 对如下类对象的反序列化: /// public sealed class RestResponse /// { /// public RestStatus StatusCode { get; set; } /// [JsonProperty("Result")] /// public IJsonContent Content { get; set; } /// } /// 这里Content是接口,在反序列化时需要具体化类型. /// 主要是在RestClient中处理响应时需要用到 /// </example> /// </summary> /// <typeparam name="TSubContentImp">JSON模型子内容,其以接口类型实现,需要根据类型具体化</typeparam> /// <param name="restService"></param> /// <param name="jsonContent"></param> /// <returns></returns> public static ResponseContent DeserializeResponse<TSubContentImp>(this RestServiceBase restService, string jsonContent) { return JsonUtils.DeserializeObject<ResponseContent, TSubContentImp>(jsonContent, JsonPropertyFilterEnum.RestResponseResult); }