Ejemplo n.º 1
0
Archivo: Json.cs Proyecto: zjbsean/TM
        public static TStrList Json2TStrList(string jsonStr)
        {
            TStrList result = null;

            if (jsonStr.Length < 3)
            {
                return(null);
            }

            jsonStr = jsonStr.Substring(1, jsonStr.Length - 2);
            string[] valArray = jsonStr.Split(',');
            for (int i = 0; i < valArray.Length; i++)
            {
                string valItem = valArray[i].Trim().Replace("\"", "");
                if (valItem == string.Empty)
                {
                    continue;
                }

                if (result == null)
                {
                    result = new TStrList();
                }

                result.Add(valItem);
            }

            return(result);
        }
Ejemplo n.º 2
0
Archivo: Json.cs Proyecto: zjbsean/TM
        /// <summary>
        /// 对象类型(即每一项都以{}包含)的数组拆分
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public static string TryJsonObj2ArrayParse(string jsonStr, out TStrList strList)
        {
            string result = null;

            strList = null;

            jsonStr = jsonStr.Substring(1, jsonStr.Length - 2);

            while (true)
            {
                int beginIndex = jsonStr.IndexOf('{');
                if (beginIndex == -1)
                {
                    break;
                }

                int endIndex = jsonStr.IndexOf('}');
                if (endIndex == -1)
                {
                    result = string.Format("JsonObjArrayParse 字符串格式不正确,没有找到反括号 jsonStr = {0}", jsonStr);
                    SvLogger.Error(result);
                    return(result);
                }

                if (beginIndex > endIndex)
                {
                    result = string.Format("JsonObjArrayParse 字符串格式不正确,正反括号位置异常  jsonStr = {0}", jsonStr);
                    SvLogger.Error(result);
                    return(result);
                }

                if (strList == null)
                {
                    strList = new TStrList();
                }

                string strItem = jsonStr.Substring(beginIndex + 1, endIndex - beginIndex - 1);
                strList.Add(strItem);

                if (endIndex + 1 == jsonStr.Length)
                {
                    break;
                }

                jsonStr = jsonStr.Substring(endIndex + 1);
            }

            return(result);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 通知玩家、角色服务分配信息
 /// </summary>
 /// <param name="playerIDList"></param>
 /// <param name="allocSvrList"></param>
 public void OnNotifyPlayerListSvrAllocInfo(ref TStrList loginNameList, ref PtPlayerAllocSvrList allocSvrList)
 {
     for (int i = 0; i < loginNameList.GetElements().Count; ++i)
     {
         UserSvrInfo svrInfo = new UserSvrInfo();
         svrInfo.m_LoginName = loginNameList.GetElements()[i];
         for (int j = 0; j < allocSvrList.GetElements().Count; ++j)
         {
             if (allocSvrList.GetElements()[j].svrType == eServerType.GAME)
             {
                 svrInfo.m_GameServerName = allocSvrList.GetElements()[j].svrName;
             }
             else if (allocSvrList.GetElements()[j].svrType == eServerType.GATEWAY)
             {
                 svrInfo.m_GateWayName = allocSvrList.GetElements()[j].svrName;
             }
         }
         AllocSvrMap.Instance.AddPlayerSvrInfo(svrInfo);
     }
 }