public static string Serializer <T>(T jsonData, bool needEncrypt = false) { if (jsonData == null) { return(default(string)); } string jsonString = ""; try { jsonString = JsonConvert.SerializeObject(jsonData); if (isShowLog) { //SQDebug.LogWarning("Json: " + jsonString); } } catch (Exception e) { SQDebug.Log(e.Message); return(default(string)); } if (needEncrypt) { jsonString = ResourcesEncryption.AES_Encrypt(jsonString); } return(jsonString); }
public static object DeserializByte(Type t, byte[] data, int index, int readCount, bool needShowLog = false) { bool needDecrypt = false; string jsonString = Encoding.UTF8.GetString(data, index, readCount); if (jsonString == default(string) || jsonString == "") { return(null); } if (isShowLog || needShowLog) { SQDebug.LogWarning("Json: " + jsonString); int i = 0; } if (needDecrypt) { jsonString = ResourcesEncryption.AES_Decrypt(jsonString); } try { return(JsonConvert.DeserializeObject(jsonString, t)); } catch (Exception e) { SQDebug.Log(e.Message); return(null); } }
public static T Deserialize <T>(string jsonString, bool needDecrypt = false) { if (jsonString == default(string) || jsonString == "") { return(default(T)); } if (isShowLog) { SQDebug.LogWarning("Json: " + jsonString); } if (needDecrypt) { jsonString = ResourcesEncryption.AES_Decrypt(jsonString); } try { return(JsonConvert.DeserializeObject <T>(jsonString)); } catch (Exception e) { SQDebug.Log(e.Message); return(default(T)); } }