Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@AndyHuang1223
Created March 1, 2022 04:50
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/bd7e83d8ae6c3d5f15d71566cb519189 to your computer and use it in GitHub Desktop.
Save AndyHuang1223/bd7e83d8ae6c3d5f15d71566cb519189 to your computer and use it in GitHub Desktop.
class Program
{
static void Main(string[] args)
{
var jsonString = CreateMockJsonString();
var isJsonFormat = jsonString.JsonTryParse<BaseModel<User>>(out var jsonResult);
if (!isJsonFormat)
{
Console.WriteLine($"{jsonString} is not JSON format !");
}
else
{
Console.WriteLine($"{jsonString} is JSON format");
Console.WriteLine($"Code : {jsonResult.Code}");
Console.WriteLine($"Msg : {jsonResult.Message}");
Console.WriteLine($"Name : {jsonResult.Response.Name}");
Console.WriteLine($"Age : {jsonResult.Response.Age}");
}
}
static string CreateMockJsonString()
{
return @"{""Code"":0,""Msg"":""Success!"",""Response"": {""Name"":""Andy"",""Age"": 30}}";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment