mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-03-12 04:35:27 -07:00
27 lines
720 B
C#
27 lines
720 B
C#
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) };
|
|
|
|
}
|
|
}
|
|
} |