As they already metioned, your JSON string is invalid that's why you are getting an error. To prevent invalid JSON string format, you could write an extension method or a static method to check of validity. For example:
public static bool IsValidJson(string strInput)
{
strInput = strInput.Trim();
if ((strInput.StartsWith("{") && strInput.EndsWith("}")) ||
(strInput.StartsWith("[") && strInput.EndsWith("]")))
{
try
{
var obj = JToken.Parse(strInput);
return true;
}
catch (JsonReaderException jex)
{
return false;
}
catch (Exception ex)
{
return false;
}
}
else
{
return false;
}
}
You can then do:
var isValid = IsValidJson(jsonString);
if(isValid){
}
Also keep note of the security risk as stated by OriginalGriff.