Skip to content

Instantly share code, notes, and snippets.

@AndyHuang1223
Last active February 25, 2022 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndyHuang1223/58a14ab4677e408f652a62b348e31ec7 to your computer and use it in GitHub Desktop.
Save AndyHuang1223/58a14ab4677e408f652a62b348e31ec7 to your computer and use it in GitHub Desktop.
public static class JsonParseExtension
{
public static bool JsonTryParse<T>(this string jsonString, out T result) where T : class
{
try
{
result = JsonSerializer.Deserialize<T>(jsonString);
return true;
}
catch(Exception e)
{
result = default;
Debug.WriteLine(e.Message);
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment