C # serialization and deserialization,
This is the deserialization code.
Using System. Runtime. Serialization. Json;
Public static T deserialize <T> (String s) {// JSON deserialization byte [] buf = Encoding. UTF8.GetBytes (s); MemoryStream MS = new MemoryStream (buf); DataContractJsonSerializer json = new DataContractJsonSerializer (typeof (T); return (T) json. readObject (MS );}
Serialization
Using Newtonsoft. Json;
Using Newtonsoft. Json. Linq;
Using System. Runtime. Serialization;
Using System. Runtime. Serialization. Json;
Static String serialize (OrderList s) {// Json serialized Object --> Json String // DataContrctJsonSerializer class DataContractJsonSerializer json = new DataContractJsonSerializer (typeof (OrderList )); // memory data stream MemoryStream MS = new MemoryStream (); // serialize to memory data stream json. writeObject (ms, s); // convert to array byte [] buf = ms. toArray (); // convert to UTF8 string return Encoding. UTF8.GetString (buf );}
To facilitate call at any time