Exemple #1
0
    private CSJSONObject parseArray()
    {
        CSJSONObject a = new CSJSONObject();

        a.f_eObjType = EJSONObjectType.eJOT_Array;
        NextToken();
        if (token.type == CSJSONTokenType.RIGHT_BRACKET)
        {
            return(a);
        }
        while (true)
        {
            a.push(ParseValue());
            NextToken();
            if (token.type == CSJSONTokenType.RIGHT_BRACKET)
            {
                return(a);
            }
            else if (token.type == CSJSONTokenType.COMMA)
            {
                NextToken();
            }
            else
            {
                Debug.LogError("Expecting ] or , but found " + token.value);
                return(null);
            }
        }
    }
Exemple #2
0
    private string ConvertToString(CSJSONObject value)
    {
        if (value == null)
        {
            return("null");
        }
        switch (value.f_eObjType)
        {
        case EJSONObjectType.eJOT_String:
            return(EscapeString(value.GetString()));

        case EJSONObjectType.eJOT_Int:
            return(value.GetInt().ToString());

        case EJSONObjectType.eJOT_Float:
            return(value.GetFloat().ToString());

        case EJSONObjectType.eJOT_Bool:
            return(value.GetBool() ? "true" : "false");

        case EJSONObjectType.eJOT_Array:
            return(ArrayToString(value.GetArray()));

        case EJSONObjectType.eJOT_Object:
            return(ObjectToString(value.GetObject()));
        }
        return("null");
    }
Exemple #3
0
    public static void SendMsg(string mod, string d, MsgCallbackDelegate func, CSJSONObject obj = null)
    {
//		string sUrl = CSUrlConst.API;
//		string sHashKey = CSGameMain.f_Common.f_sHashKey;
//		if (sHashKey == null || sHashKey == "") {
//			return;
//		}
//		sUrl += "?m=" + mod + "&d=" + d + "&r=" + CSJSON.Encode(obj) + "&hashKey=" + sHashKey + "&t=" + Random.value;
//		CallbackDelegate callback = (string sData) => {
//			func(CSJSON.Decode(sData));
//		};
//		SCRMain.Coroutine(HttpRequest(sUrl, callback));
    }
Exemple #4
0
    private CSJSONObject parseObject()
    {
        CSJSONObject o = new CSJSONObject();

        o.f_eObjType = EJSONObjectType.eJOT_Object;
        string key;

        NextToken();
        if (token.type == CSJSONTokenType.RIGHT_BRACE)
        {
            return(o);
        }
        while (true)
        {
            if (token.type == CSJSONTokenType.STRING)
            {
                key = token.stringValue;
                NextToken();
                if (token.type == CSJSONTokenType.COLON)
                {
                    NextToken();
                    o[key] = ParseValue();
                    NextToken();
                    if (token.type == CSJSONTokenType.RIGHT_BRACE)
                    {
                        return(o);
                    }
                    else if (token.type == CSJSONTokenType.COMMA)
                    {
                        NextToken();
                    }
                    else
                    {
                        Debug.LogError("Expecting } or , but found " + token.value);
                        return(null);
                    }
                }
                else
                {
                    Debug.LogError("Expecting : but found " + token.value);
                    return(null);
                }
            }
            else
            {
                Debug.LogError("Expecting string but found " + token.value);
                return(null);
            }
        }
    }
Exemple #5
0
 public void push(CSJSONObject obj)
 {
     m_lstObject.Add(obj);
 }
Exemple #6
0
 public CSJSONDecoder(string s)
 {
     tokenizer = new CSJSONTokenizer(s);
     NextToken();
     value = ParseValue();
 }
Exemple #7
0
    public static string Encode(CSJSONObject o)
    {
        CSJSONEncoder encoder = new CSJSONEncoder(o);

        return(encoder.GetString());
    }
Exemple #8
0
 public CSJSONEncoder(CSJSONObject value)
 {
     jsonString = ConvertToString(value);
 }