Esempio n. 1
0
        public static JSONNode Deserialize(System.IO.BinaryReader aReader)
        {
            JSONNodeType type = (JSONNodeType)aReader.ReadByte();

            switch (type)
            {
            case JSONNodeType.Array:
            {
                int       count = aReader.ReadInt32();
                JSONArray tmp   = Johny.JSONNodePool.Claim(typeof(JSONArray)).AsArray;
                for (int i = 0; i < count; i++)
                {
                    tmp.Add(Deserialize(aReader));
                }
                return(tmp);
            }

            case JSONNodeType.Object:
            {
                int        count = aReader.ReadInt32();
                JSONObject tmp   = Johny.JSONNodePool.Claim(typeof(JSONObject)).AsObject;
                for (int i = 0; i < count; i++)
                {
                    string key = aReader.ReadString();
                    var    val = Deserialize(aReader);
                    tmp.Add(key, val);
                }
                return(tmp);
            }

            case JSONNodeType.String:
            {
                JSONString jstring = Johny.JSONNodePool.Claim(typeof(JSONString)) as JSONString;
                jstring.InitString(aReader.ReadString());
                return(jstring);
            }

            case JSONNodeType.Number:
            {
                return(new JSONNumber(aReader.ReadDouble()));
            }

            case JSONNodeType.Boolean:
            {
                return(new JSONBool(aReader.ReadBoolean()));
            }

            case JSONNodeType.NullValue:
            {
                return(new JSONNull());
            }

            default:
            {
                throw new Exception("Error deserializing JSON. Unknown tag: " + type);
            }
            }
        }
        public static JSONNode DeserializeBinary(BinaryReader aReader)
        {
            JSONNodeType type = (JSONNodeType)aReader.ReadByte();

            switch (type)
            {
            case JSONNodeType.Array:
            {
                int       count = aReader.ReadInt32();
                JSONArray tmp   = new JSONArray();
                for (int i = 0; i < count; i++)
                {
                    tmp.Add(DeserializeBinary(aReader));
                }
                return(tmp);
            }

            case JSONNodeType.Object:
            {
                int        count = aReader.ReadInt32();
                JSONObject tmp   = new JSONObject();
                for (int i = 0; i < count; i++)
                {
                    string   key = aReader.ReadString();
                    JSONNode val = DeserializeBinary(aReader);
                    tmp.Add(key, val);
                }

                return(tmp);
            }

            case JSONNodeType.String:
            {
                return(new JSONString(aReader.ReadString()));
            }

            case JSONNodeType.Number:
            {
                return(new JSONNumber(aReader.ReadDouble()));
            }

            case JSONNodeType.Boolean:
            {
                return(new JSONBool(aReader.ReadBoolean()));
            }

            case JSONNodeType.NullValue:
            {
                return(JSONNull.CreateOrGet());
            }

            default:
            {
                throw new Exception("Error deserializing JSON. Unknown tag: " + type);
            }
            }
        }
Esempio n. 3
0
        public static JSONNode DeserializeBinary(BinaryReader aReader)
        {
            JSONNodeType jSONNodeType = (JSONNodeType)aReader.ReadByte();

            switch (jSONNodeType)
            {
            case JSONNodeType.Array:
            {
                int       num2      = aReader.ReadInt32();
                JSONArray jSONArray = new JSONArray();
                for (int j = 0; j < num2; j++)
                {
                    jSONArray.Add(DeserializeBinary(aReader));
                }
                return(jSONArray);
            }

            case JSONNodeType.Object:
            {
                int        num        = aReader.ReadInt32();
                JSONObject jSONObject = new JSONObject();
                for (int i = 0; i < num; i++)
                {
                    string   aKey  = aReader.ReadString();
                    JSONNode aItem = DeserializeBinary(aReader);
                    jSONObject.Add(aKey, aItem);
                }
                return(jSONObject);
            }

            case JSONNodeType.String:
                return(new JSONString(aReader.ReadString()));

            case JSONNodeType.Number:
                return(new JSONNumber(aReader.ReadDouble()));

            case JSONNodeType.Boolean:
                return(new JSONBool(aReader.ReadBoolean()));

            case JSONNodeType.NullValue:
                return(JSONNull.CreateOrGet());

            default:
                throw new Exception("Error deserializing JSON. Unknown tag: " + jSONNodeType);
            }
        }
Esempio n. 4
0
        public static JSONNode Deserialize(BinaryReader aReader)
        {
            JSONNodeType type = (JSONNodeType)aReader.ReadByte();

            switch (type)
            {
            case JSONNodeType.Array:
            {
                int       num   = aReader.ReadInt32();
                JSONArray array = new JSONArray();
                for (int i = 0; i < num; i++)
                {
                    array.Add(Deserialize(aReader));
                }
                return(array);
            }

            case JSONNodeType.Object:
            {
                int        num3 = aReader.ReadInt32();
                JSONObject obj2 = new JSONObject();
                for (int i = 0; i < num3; i++)
                {
                    string   aKey  = aReader.ReadString();
                    JSONNode aItem = Deserialize(aReader);
                    obj2.Add(aKey, aItem);
                }
                return(obj2);
            }

            case JSONNodeType.String:
                return(new JSONString(aReader.ReadString()));

            case JSONNodeType.Number:
                return(new JSONNumber(aReader.ReadDouble()));

            case JSONNodeType.NullValue:
                return(new JSONNull());

            case JSONNodeType.Boolean:
                return(new JSONBool(aReader.ReadBoolean()));
            }
            throw new Exception("Error deserializing JSON. Unknown tag: " + type);
        }