public static string Serialize <T>(T message) { JSONOutStream jSONOutStream = new JSONOutStream(); SerializeObject(jSONOutStream, typeof(T), message); return(jSONOutStream.Serialize()); }
public static string Serialize(object message, Type type) { JSONOutStream jSONOutStream = new JSONOutStream(); SerializeObject(jSONOutStream, type, message); return(jSONOutStream.Serialize()); }
void ExampleBasicJSON() { // Let's serialize a simple address book JSONOutStream outStream = new JSONOutStream(); outStream.Content("a", 1) .Content("b", 2) .Start("c") .Content("d", 3) .End(); string serialized = outStream.Serialize(); // serialized outputs this JSON structure: // {a:1, b: 2, c: {d: 3}} // Deserialize it JSONInStream inStream = new JSONInStream(serialized); int a, b, d; inStream.Content("a", out a) .Content("b", out b) .Start("c") .Content("d", out d) .End(); Debug.Log("SERIALIZED JSON STRING: " + serialized); Debug.Log("JSON DESERIALIZATION of a:" + a + ", b: " + b + ", d: " + d); }
/// <summary> /// 保存reslist.json的內容 /// </summary> /// <param name="fileInfo"></param> /// <param name="data"></param> /// <param name="reslistVersion"></param> static private void SaveReslist(FileInfo fileInfo, Dictionary <string, AssetBundleInfo> data, int reslistVersion) { //生成新的json文件 JSONOutStream jOutStream = new JSONOutStream(); jOutStream.Content("version", reslistVersion) .List("assets"); foreach (var pair in data) { AssetBundleInfo info = pair.Value; jOutStream.Start(0) .Content("assetbundlename", info.Path) .Content("version", info.Version) .Content("hash", info.Hash) .Content("size", info.Size) .Content("packaged", info.Packaged ? 1 : 0) .End(); } jOutStream.End(); //寫入reslist.json File.WriteAllText(fileInfo.FullName, jOutStream.Serialize()); }
public string Serialize() { JSONOutStream outStream = new JSONOutStream(); SerializeData(outStream); return(outStream.Serialize()); }
void ExampleBasicJSON() { // Let's serialize a simple address book JSONOutStream outStream = new JSONOutStream(); outStream.Content("a", 1) .Content("b", 2) .Start("c") .Content("d", 3) .End(); string serialized = outStream.Serialize(); // serialized outputs this JSON structure: // {a:1, b: 2, c: {d: 3}} // Deserialize it JSONInStream inStream = new JSONInStream(serialized); int a, b, d; inStream.Content("a", out a) .Content("b", out b) .Start("c") .Content("d", out d) .End(); Debug.Log("SERIALIZED JSON STRING: " + serialized); Debug.Log("JSON DESERIALIZATION of a:" + a + ", b: " + b + ", d: " + d ); }
//--------------------------------------------------------------------------------- // static Serialize //--------------------------------------------------------------------------------- public static string Serialize <T>(T message) { #if UNITY_FLASH && !UNITY_EDITOR Debug.LogError("JSONSerializer do not work with Flash !"); return(null); #else JSONOutStream stream = new JSONOutStream(); SerializeObject(stream, typeof(T), message); return(stream.Serialize()); #endif }