You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Ombi/src/Ombi.Helpers/JsonConvertHelper.cs

27 lines
720 B

using Newtonsoft.Json;
namespace Ombi.Helpers
{
public static class JsonConvertHelper
{
public static T[] ParseObjectToArray<T>(object ambiguousObject)
{
var json = ambiguousObject.ToString();
if (string.IsNullOrWhiteSpace(json))
{
return new T[0]; // Could return null here instead.
}
if (json.TrimStart().StartsWith("["))
{
return JsonConvert.DeserializeObject<T[]>(json);
}
if (json.TrimStart().Equals("{}"))
{
return new T[0];
}
return new T[1] { JsonConvert.DeserializeObject<T>(json) };
}
}
}