Home > Net >  The content of the uncertain type of Json format? (deserialization)
The content of the uncertain type of Json format? (deserialization)

Time:01-19

I created a class:

Public class WebSocketBase
{
Int code {get; set; }
Bool command {get; set; }
T the content {get; set; }
}

Is mainly used to accept the WebSocket sent information,
But different code code, will have different content, how do I determine the value of code, first
Then use the corresponding deserialization class go? Thank you for your attention:)

Using JsonConvert DeserializeObject,

CodePudding user response:

In terms of words, since the communication is using json into dynamic type dynamic
As follows:
 
Var Object=JsonConvert. DeserializeObject (json);
Var code=Object (" code ");

So can access code is the corresponding value through the code to match the T type
  •  Tags:  
  • C#
  • Related