how to test if string is a valid json string c#
private static bool IsValidJson(string strInput)
{
if (string.IsNullOrWhiteSpace(strInput)) { return false;}
strInput = strInput.Trim();
if ((strInput.StartsWith("{") && strInput.EndsWith("}")) || //For object
(strInput.StartsWith("[") && strInput.EndsWith("]"))) //For array
{
try
{
var obj = JToken.Parse(strInput);
return true;
}
catch (JsonReaderException jex)
{
//Exception in parsing json
Console.WriteLine(jex.Message);
return false;
}
catch (Exception ex) //some other exception
{
Console.WriteLine(ex.ToString());
return false;
}
}
else
{
return false;
}
}
Also in JavaScript:
- javascript string proper case
- javascript get first 10 characters of string
- Use the parseInt Function with a Radix Javascript
- npm start react
- js get object keys
- how to test on user reaction discord.js
- notification dropdown bootstrap
- check if textbox is focused jquery
- js escape characters
- interval javascript
- identify chrome on android using javascript
- get pods on specific node
- js detect if content editable div is empty
- use callback vs use memo
- empty path redirection on home page in angular routing
- npm nodemon -v global
- check if object is empty javascript
- typescript read json file
- how to delay iterations in javascript
- we need a server for server side rendering of angular
- using server passed values and client js together in ejs
- javascript function with array parameter
- d3 script
- jquery remove css