Net.Bluewalk.DotNetUtils/Extensions/StringExtensions.cs
/// <summary>
/// Determines whether string is valid JSON.
/// </summary>
/// <param name="value">The value.</param>
/// <returns><c>true</c> if [is valid json] [the specified value]; otherwise, <c>false</c>.</returns>
Determines whether string is valid JSON.
Determines whether string is valid JSON .
public static bool IsValidJson(this string value)
        {
            if (string.IsNullOrEmpty(value)) return false;
            value = value.Trim();
            if ((!value.StartsWith("\"") || !value.EndsWith("\"")) &&
                (!value.StartsWith("{") || !value.EndsWith("}")) &&
                (!value.StartsWith("[") || !value.EndsWith("]"))) return false;
            try
            {
                JToken.Parse(value);
                return true;
            }
            catch (Exception) 
            {
                return false;
            }
        }
public static bool IsValidJson ( this string value ) { if ( string . IsNullOrEmpty ( value ) ) return false ; value = value . Trim ( ) ; if ( ( ! value . StartsWith ( " \" " ) || ! value . EndsWith ( " \" " ) ) && ( ! value . StartsWith ( " " ) || ! value . EndsWith ( " " ) ) && ( ! value . StartsWith ( " " ) || ! value . EndsWith ( " " ) ) ) return false ; try { JToken . Parse ( value ) ; return true ; } catch ( Exception ) { return false ; } }
Determines whether string is valid JSON.
Determines whether string is valid JSON .
//some other exception
None
string
this
value
None