Exemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        string xx = "10";
        int    b  = (int)JsonMapper.DeserializeObject(xx, typeof(int));

        print(b);
    }
Exemplo n.º 2
0
        public static T CreateHttpProxy <T>(Type obj, string methodName, List <string> args, short gameId)
        {
            ClientHttpRequsetIoMessage ioMessage = new ClientHttpRequsetIoMessage();

            ioMessage.interfaceName = obj.FullName;
            ioMessage.methodName    = methodName;
            // client.args = JsonConvert.SerializeObject(callMessage.Args);
            if (args != null)
            {
                ioMessage.args = JsonMapper.ToJson(args);
            }
            else
            {
                ioMessage.args = null;
            }
            HttpIoMessage resultMessage = HttpSocketImpl.getInstance().sync(ioMessage, gameId);

            if (resultMessage != null)
            {
                if (resultMessage.resultCode == 200)
                {
                    // object o = JsonConvert.DeserializeObject(resultMessage.msg, returnType);
                    object o = JsonMapper.DeserializeObject(resultMessage.msg, typeof(T));
                    return((T)o);
                }
                else if (resultMessage.resultCode == 404)
                {
                    //异常处理
                    ErrorImpl error     = new ErrorImpl();
                    string[]  strs      = resultMessage.msg.Split(',');
                    string[]  errMsg    = null;
                    int       errorCode = 0;
                    if (strs.Length > 1)
                    {
                        errorCode = int.Parse(strs[0]);
                        errMsg    = new string[strs.Length - 1];
                        for (int i = 1; i < strs.Length; i++)
                        {
                            errMsg[i - 1] = strs[i];
                        }
                    }
                    else if (strs.Length == 1)
                    {
                        errorCode = int.Parse(strs[0]);
                    }
                    error.err(errorCode, errMsg);
                    return(default(T));
                }
                return(default(T));
            }
            else
            {
                return(default(T));
            }
        }
Exemplo n.º 3
0
    void Handler(ClientTcpIoMessage ioMessage)
    {
        if (ioMessage.methodName.Equals("error"))
        {
            //异常处理
            ErrorImpl     error     = new ErrorImpl();
            List <string> list      = JsonMapper.ToObject <List <string> >(ioMessage.args);
            int           errorCode = int.Parse(list[0]);
            string[]      str       = null;
            if (list.Count > 1)
            {
                if (!list[1].Equals("null"))
                {
                    str = list[1].Split(',');
                }
            }
            error.err(errorCode, str);
        }
        else
        {
            if (TcpManager.Instance.dict.ContainsKey(ioMessage.interfaceName))
            {
                if (TcpManager.Instance.dict[ioMessage.interfaceName].ParamInfo.ContainsKey(ioMessage.methodName))
                {
                    ILRuntimeParameterInfo[] paramInfo = TcpManager.Instance.dict[ioMessage.interfaceName].ParamInfo[ioMessage.methodName];

                    object[] args = null;
                    if (paramInfo.Length > 0)
                    {
                        args = new object[paramInfo.Length];
                        //List<string> list = JsonConvert.DeserializeObject<List<string>>(ioMessage.args);
                        List <string> list = JsonMapper.ToObject <List <string> >(ioMessage.args);
                        if (list.Count != paramInfo.Length)
                        {
                            //错误参数
                            throw new NullReferenceException("错误参数");
                        }
                        for (int i = 0; i < paramInfo.Length; i++)
                        {
                            // args[i] = JsonConvert.DeserializeObject(list[i], paramInfo[i].ParameterType);
                            args[i] = JsonMapper.DeserializeObject(list[i], paramInfo[i].ParameterType);
                        }
                    }
                    if (TcpManager.Instance.dict[ioMessage.interfaceName].MetnodInfo.ContainsKey(ioMessage.methodName))
                    {
                        TcpManager.Instance.dict[ioMessage.interfaceName].MetnodInfo[ioMessage.methodName].Invoke(TcpManager.Instance.dict[ioMessage.interfaceName].ObjInstance, args);
                    }

                    // ILMgr.Instance.appDomain.Invoke(IoMessageHandler.getInstance().dict[ioMessage.interfaceName].ObjName, ioMessage.methodName, IoMessageHandler.getInstance().dict[ioMessage.interfaceName].ObjInstance, args);
                }
            }
        }
    }
Exemplo n.º 4
0
    public static void loadStaticDatable()
    {
        //if()最新版本
        // String data= PlayerPrefs.GetString("Data");
        //else {
        // DbDatableInfo info = InvokeService.Proxy<DbDatableInfo>();
        DatableModelListDto dto = ProxyObj.CreateHttpProxy <DatableModelListDto>(typeof(DbDatableInfo), "getData", null, -7);
        //DatableModelListDto dto = info.getData();
        List <DatableModelDto> dtos = dto.msgList;

        if (dtos != null && dtos.Count > 0)
        {
            foreach (DatableModelDto d in dtos)
            {
                Type t = Type.GetType(d.objType);
                // IType t = ILMgr.Instance.appDomain.LoadedTypes[d.objType];
                // object t = StaticDataHandler.Instance.staticDataDic[d.objType];

                Dictionary <int, object> dice = new Dictionary <int, object>();

                foreach (string s in d.jsonMsg)
                {
                    object o = JsonMapper.DeserializeObject(s, t);

                    DataTableMessage dataTable = (DataTableMessage)o;
                    if (dice.ContainsKey(dataTable.Id()))
                    {
                        dice.Remove(dataTable.Id());

                        dice.Add(dataTable.Id(), dataTable);
                    }
                    else
                    {
                        dice.Add(dataTable.Id(), dataTable);
                    }
                }

                StaticConfigMessage.Instance.put(t, dice);
            }
        }
        // string str = JsonConvert.SerializeObject(dto);
        string str = JsonMapper.ToJson(dto);

        if (PlayerPrefs.HasKey("Data"))
        {
            PlayerPrefs.DeleteKey("Data");
            PlayerPrefs.SetString("Data", str);
        }
        //}
    }