showing results for - "how to test if string is a valid json string c 23"
Angelina
04 Oct 2016
1private static bool IsValidJson(string strInput)
2{
3    if (string.IsNullOrWhiteSpace(strInput)) { return false;}
4    strInput = strInput.Trim();
5    if ((strInput.StartsWith("{") && strInput.EndsWith("}")) || //For object
6        (strInput.StartsWith("[") && strInput.EndsWith("]"))) //For array
7    {
8        try
9        {
10            var obj = JToken.Parse(strInput);
11            return true;
12        }
13        catch (JsonReaderException jex)
14        {
15            //Exception in parsing json
16            Console.WriteLine(jex.Message);
17            return false;
18        }
19        catch (Exception ex) //some other exception
20        {
21            Console.WriteLine(ex.ToString());
22            return false;
23        }
24    }
25    else
26    {
27        return false;
28    }
29}
queries leading to this page
c 23 check for valid jsonvalidate if string is correct json c 23how to check a json for text c 23validate if string is json c 23check json string valid c 23c 23 validate json objecthow to validate a json property in c 23c 23 check if data is jsonhow to validate json response in c 23check string is valid json c 23check if json is valid c 23how to check json is valid or not in c 23how to check if a string is a json c 23check valid json c 23c 23 check if is jsonhow to test if string is a valid json string c 23how to check json string is correct or not in c 23how to check if string is a valid json c 23validating number in json c 23c 23 is json validcheck if string is json or not c 23detect a json nethow to check json valid c 23c 23 check if json is validjson net check if valid jsonhow to chekc if a strign has a valid json c 23c 23 check if json filec 23 check if string is valid jsoncheck if string is json c 23c 23 check if string valid json net check if valid json generichow to valid json in c 23validate json string c 23how to check if json string is json value in c 23check if string is json string c 23c 23 json validate stringcheck if string is valid json c 23 c 23 get if json is a valid c 23 objectc 23 how to validate jsonc 23 validate a string is in json formattest if string is valid json c 23c 23 get if string is valid jsonc 23 check if string is json string of certain objectc 23 validate json syntaxnewtonsoft json jsonconvert check if string is valid jsonhow to validate a json in c 23validate json checker c 23check if file is json c 23c 23 check if jsonhow to validate a value of a json property in c 23c 23 check valid jsonc 23 check if valid jsonc 23 check if string is jsoncheck if a string is valid json c 23c 23 validate jsonvalidate string is json c 23c 23 how to validate if string is jsonc 23 json get if string is valit jsonc 23 check json is validvalidate json c 23how to check whether a string is json or not in c 23how to test if string is a valid json string c 23