Created
March 1, 2022 04:50
-
-
Save AndyHuang1223/bd7e83d8ae6c3d5f15d71566cb519189 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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