public static T Unwrap <T>(string jsonString, string propertyToUnwrap = "", bool ignoreCase = true) { WrapTo <T> data = null; if (string.IsNullOrEmpty(propertyToUnwrap)) { data = DN.JsonSerializer.Deserialize <WrapTo <T> >(jsonString, JsonSettings.DotNetJsonSettings(ignoreCase)); return(data.Result); } else { data = NS.JsonConvert.DeserializeObject <WrapTo <T> >(jsonString, JsonSettings.NewtonsoftJsonSettings <WrapTo <T> >(propertyToUnwrap)); return(data.Result); } }
private static async Task <HttpResponseMessage> UnWrapResponse(string propertyToUnwrap, HttpResponseMessage response) { if (!response.IsSuccessStatusCode) { return(response); } var contentResult = await response.Content.ReadAsStringAsync(); AutoWrapperResponse data = new AutoWrapperResponse(); string content = string.Empty; if (string.IsNullOrEmpty(propertyToUnwrap)) { data = DN.JsonSerializer.Deserialize <AutoWrapperResponse>(contentResult, JsonSettings.DotNetJsonSettings()); content = DN.JsonSerializer.Serialize(data.Result); } else { data = NS.JsonConvert.DeserializeObject <AutoWrapperResponse>(contentResult, JsonSettings.NewtonsoftJsonSettings(propertyToUnwrap)); content = NS.JsonConvert.SerializeObject(data.Result); } var unwrappedResponse = new HttpResponseMessage(response.StatusCode) { Content = new StringContent(content, Encoding.UTF8, "application/json") }; foreach (var header in response.Headers) { unwrappedResponse.Headers.Add(header.Key, header.Value); } return(unwrappedResponse); }