コード例 #1
0
        private static Dictionary <string, JSONValue> ParseJSON(string content, out string status, out string message)
        {
            message = (string)null;
            status  = (string)null;
            JSONValue jsonValue;

            try
            {
                jsonValue = new JSONParser(content).Parse();
            }
            catch (JSONParseException ex)
            {
                Debug.Log((object)("Error parsing server reply: " + content));
                Debug.Log((object)ex.Message);
                return((Dictionary <string, JSONValue>)null);
            }
            Dictionary <string, JSONValue> dictionary;

            try
            {
                dictionary = jsonValue.AsDict(true);
                if (dictionary == null)
                {
                    Debug.Log((object)("Error parsing server message: " + content));
                    return((Dictionary <string, JSONValue>)null);
                }
                if (dictionary.ContainsKey("result") && dictionary["result"].IsDict())
                {
                    dictionary = dictionary["result"].AsDict(true);
                }
                if (dictionary.ContainsKey("message"))
                {
                    message = dictionary["message"].AsString(true);
                }
                if (dictionary.ContainsKey("status"))
                {
                    status = dictionary["status"].AsString(true);
                }
                else if (dictionary.ContainsKey("error"))
                {
                    status = dictionary["error"].AsString(true);
                    if (status == string.Empty)
                    {
                        status = "ok";
                    }
                }
                else
                {
                    status = "ok";
                }
            }
            catch (JSONTypeException ex)
            {
                Debug.Log((object)("Error parsing server reply. " + content));
                Debug.Log((object)ex.Message);
                return((Dictionary <string, JSONValue>)null);
            }
            return(dictionary);
        }