mirror of
https://github.com/status-im/nft-faucet.git
synced 2025-02-24 12:38:30 +00:00
28 lines
598 B
C#
28 lines
598 B
C#
|
using Newtonsoft.Json;
|
||
|
using Newtonsoft.Json.Linq;
|
||
|
|
||
|
namespace NftFaucet.Extensions;
|
||
|
|
||
|
public static class StringExtensions
|
||
|
{
|
||
|
public static bool IsValidJson(this string str)
|
||
|
{
|
||
|
if (string.IsNullOrWhiteSpace(str))
|
||
|
return false;
|
||
|
|
||
|
str = str.Trim();
|
||
|
if ((!str.StartsWith("{") || !str.EndsWith("}")) && (!str.StartsWith("[") || !str.EndsWith("]")))
|
||
|
return false;
|
||
|
|
||
|
try
|
||
|
{
|
||
|
var _ = JToken.Parse(str);
|
||
|
return true;
|
||
|
}
|
||
|
catch (JsonReaderException)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
}
|