public static JSONNode Deserialize(BinaryReader aReader) { JSONBinaryTag jSONBinaryTag = (JSONBinaryTag)aReader.ReadByte(); JSONNode result; switch (jSONBinaryTag) { case JSONBinaryTag.Array: { int num = aReader.ReadInt32(); JSONArray jSONArray = new JSONArray(); for (int i = 0; i < num; i++) { jSONArray.Add(JSONNode.Deserialize(aReader)); } result = jSONArray; break; } case JSONBinaryTag.Class: { int num2 = aReader.ReadInt32(); JSONClass jSONClass = new JSONClass(); for (int j = 0; j < num2; j++) { string aKey = aReader.ReadString(); JSONNode aItem = JSONNode.Deserialize(aReader); jSONClass.Add(aKey, aItem); } result = jSONClass; break; } case JSONBinaryTag.Value: result = new JSONData(aReader.ReadString()); break; case JSONBinaryTag.IntValue: result = new JSONData(aReader.ReadInt32()); break; case JSONBinaryTag.DoubleValue: result = new JSONData(aReader.ReadDouble()); break; case JSONBinaryTag.BoolValue: result = new JSONData(aReader.ReadBoolean()); break; case JSONBinaryTag.FloatValue: result = new JSONData(aReader.ReadSingle()); break; default: throw new Exception("Error deserializing JSON. Unknown tag: " + jSONBinaryTag); } return(result); }
public static JSONNode Deserialize(System.IO.BinaryReader aReader) { JSONBinaryTag type = (JSONBinaryTag)aReader.ReadByte(); switch (type) { case JSONBinaryTag.Array: { int count = aReader.ReadInt32(); JSONArray tmp = new JSONArray(); for (int i = 0; i < count; i++) { tmp.Add(Deserialize(aReader)); } return(tmp); } case JSONBinaryTag.Class: { int count = aReader.ReadInt32(); JSONClass tmp = new JSONClass(); for (int i = 0; i < count; i++) { string key = aReader.ReadString(); var val = Deserialize(aReader); tmp.Add(key, val); } return(tmp); } case JSONBinaryTag.Value: { return(new JSONData(aReader.ReadString())); } case JSONBinaryTag.IntValue: { return(new JSONData(aReader.ReadInt32())); } case JSONBinaryTag.LongValue: { return(new JSONData(aReader.ReadInt64())); } case JSONBinaryTag.DoubleValue: { return(new JSONData(aReader.ReadDouble())); } case JSONBinaryTag.BoolValue: { return(new JSONData(aReader.ReadBoolean())); } case JSONBinaryTag.FloatValue: { return(new JSONData(aReader.ReadSingle())); } default: { throw new Exception("Error deserializing JSON. Unknown tag: " + type); } } }
public static JSONNode Deserialize(BinaryReader aReader) { JSONBinaryTag jSONBinaryTag = (JSONBinaryTag)aReader.ReadByte(); switch (jSONBinaryTag) { case JSONBinaryTag.Array: { int num = aReader.ReadInt32(); JSONArray jSONArrays = new JSONArray(); for (int i = 0; i < num; i++) { jSONArrays.Add(JSONNode.Deserialize(aReader)); } return(jSONArrays); } case JSONBinaryTag.Class: { int num1 = aReader.ReadInt32(); JSONClass jSONClasses = new JSONClass(); for (int j = 0; j < num1; j++) { jSONClasses.Add(aReader.ReadString(), JSONNode.Deserialize(aReader)); } return(jSONClasses); } case JSONBinaryTag.Value: { return(new JSONData(aReader.ReadString())); } case JSONBinaryTag.IntValue: { return(new JSONData(aReader.ReadInt32())); } case JSONBinaryTag.DoubleValue: { return(new JSONData(aReader.ReadDouble())); } case JSONBinaryTag.BoolValue: { return(new JSONData(aReader.ReadBoolean())); } case JSONBinaryTag.FloatValue: { return(new JSONData(aReader.ReadSingle())); } } throw new Exception(string.Concat("Error deserializing JSON. Unknown tag: ", jSONBinaryTag)); }
public JSONData(string aData) { m_Data = aData; // check for number if (m_Regex.IsMatch(m_Data)) { m_Type = JSONBinaryTag.Number; } else { m_Type = JSONBinaryTag.String; } }
public static JSONNode Deserialize(BinaryReader aReader) { JSONBinaryTag jsonbinaryTag = (JSONBinaryTag)aReader.ReadByte(); switch (jsonbinaryTag) { case JSONBinaryTag.Array: { Int32 num = aReader.ReadInt32(); JSONArray jsonarray = new JSONArray(); for (Int32 i = 0; i < num; i++) { jsonarray.Add(JSONNode.Deserialize(aReader)); } return(jsonarray); } case JSONBinaryTag.Class: { Int32 num2 = aReader.ReadInt32(); JSONClass jsonclass = new JSONClass(); for (Int32 j = 0; j < num2; j++) { String aKey = aReader.ReadString(); JSONNode aItem = JSONNode.Deserialize(aReader); jsonclass.Add(aKey, aItem); } return(jsonclass); } case JSONBinaryTag.Value: return(new JSONData(aReader.ReadString())); case JSONBinaryTag.IntValue: return(new JSONData(aReader.ReadInt32())); case JSONBinaryTag.DoubleValue: return(new JSONData(aReader.ReadDouble())); case JSONBinaryTag.BoolValue: return(new JSONData(aReader.ReadBoolean())); case JSONBinaryTag.FloatValue: return(new JSONData(aReader.ReadSingle())); default: throw new Exception("Error deserializing JSON. Unknown tag: " + jsonbinaryTag); } }
public static JSONNode Deserialize(BinaryReader aReader) { JSONBinaryTag tag = (JSONBinaryTag)aReader.ReadByte(); switch (tag) { case JSONBinaryTag.Array: { int num = aReader.ReadInt32(); JSONArray array = new JSONArray(); for (int i = 0; i < num; i++) { array.Add(Deserialize(aReader)); } return(array); } case JSONBinaryTag.Class: { int num3 = aReader.ReadInt32(); JSONClass class2 = new JSONClass(); for (int j = 0; j < num3; j++) { string aKey = aReader.ReadString(); JSONNode aItem = Deserialize(aReader); class2.Add(aKey, aItem); } return(class2); } case JSONBinaryTag.Value: return(new JSONData(aReader.ReadString())); case JSONBinaryTag.IntValue: return(new JSONData(aReader.ReadInt32())); case JSONBinaryTag.DoubleValue: return(new JSONData(aReader.ReadDouble())); case JSONBinaryTag.BoolValue: return(new JSONData(aReader.ReadBoolean())); case JSONBinaryTag.FloatValue: return(new JSONData(aReader.ReadSingle())); } throw new Exception("Error deserializing JSON. Unknown tag: " + tag); }
/// <summary> /// Gets the JSON key value pair /// </summary> /// <returns>The JSON key value.</returns> /// <param name="name">Name.</param> /// <param name="aValue">A value.</param> /// <typeparam name="T">The 1st type parameter.</typeparam> public static string getJSONKeyValue <T> (T aValue, string name = "") { JSONBinaryTag tag = JSONPersistor.GetJSONBinaryTag <T> (aValue); Debug.Log("tag: " + tag); if (aValue.GetType().IsPrimitive) { //val.GetType().ToString() if (string.IsNullOrEmpty(name)) { name = "someValue"; } return("\"" + tag + "_" + name + "\"" + separator + "\"" + aValue.ToString() + "\""); /* } else if (tag == JSONBinaryTag.Array) { * * string arrayStr = name + " [ "; * JSONArray arr = (JSONArray)aValue; * * if (arr.Count > 0) { * int i = 0; * foreach (JSONNode node in arr.Childs) { * if (i > 0) { * arrayStr += " , "; * } * arrayStr += node.Value; * i++; * } * * } * arrayStr += " ]"; * * return arrayStr;*/ } else if (tag == JSONBinaryTag.Class) { JSONClass jClass = aValue as JSONClass; return(jClass.SaveToBase64()); //} else if (aValue.GetType ().IsClass) { } return(""); }
public JSONData(int aData) { AsInt = aData; tag = JSONBinaryTag.IntValue; }
public JSONData(bool aData) { AsBool = aData; tag = JSONBinaryTag.BoolValue; }
public JSONData(double aData) { AsDouble = aData; tag = JSONBinaryTag.DoubleValue; }
public JSONData(float aData) { AsFloat = aData; tag = JSONBinaryTag.FloatValue; }
public JSONData(long aData) { AsLong = aData; tag = JSONBinaryTag.IntValue; }
public JSONData(string aData) { m_Data = aData; tag = JSONBinaryTag.Value; }