コード例 #1
0
        public static PlayerResponse ToObject(string jsonStr)
        {
            var jsonObject = JSON.Parse(jsonStr);
            var obj        = new PlayerResponse();

            obj.ConnectedDeviceCount = (int)jsonObject["ConnectedDeviceCount"];


            obj.RegisteredKeys = new List <string>();
            foreach (var jsonValue in jsonObject["RegisteredKeys"].AsArray)
            {
                obj.RegisteredKeys.Add(jsonValue.Value);
            }

            obj.ActiveKeys = new List <string>();
            foreach (var jsonValue in jsonObject["ActiveKeys"].AsArray)
            {
                obj.ActiveKeys.Add(jsonValue.Value);
            }

            obj.ConnectedPositions = new List <PositionType>();
            foreach (var jsonValue in jsonObject["ConnectedPositions"].AsArray)
            {
                obj.ConnectedPositions.Add(EnumParser.ToPositionType(jsonValue.Value));
            }

            obj.Status = new Dictionary <string, int[]>();

            var status = jsonObject[("Status")];

            foreach (var statusKey in status.Keys)
            {
                var arr  = status[statusKey];
                var item = new int[arr.Count];
                var i    = 0;
                foreach (var jsonValue in arr)
                {
                    item[i] = jsonValue.Value.AsInt;
                    i++;
                }
                obj.Status[statusKey] = item;
            }

            return(obj);
        }
コード例 #2
0
ファイル: PlayerRequest.cs プロジェクト: Changmok/tac-sharp
        internal static PlayerResponse ToObject(string jsonStr)
        {
            JsonObject jsonObject = JsonObject.Parse(jsonStr);
            var        obj        = new PlayerResponse();

            obj.ConnectedDeviceCount = (int)jsonObject.GetNamedNumber("ConnectedDeviceCount");

            obj.RegisteredKeys = new List <string>();
            foreach (var jsonValue in jsonObject.GetNamedArray("RegisteredKeys", new JsonArray()))
            {
                obj.RegisteredKeys.Add(jsonValue.GetString());
            }

            obj.ActiveKeys = new List <string>();
            foreach (var jsonValue in jsonObject.GetNamedArray("ActiveKeys", new JsonArray()))
            {
                obj.ActiveKeys.Add(jsonValue.GetString());
            }

            obj.ConnectedPositions = new List <PositionType>();
            foreach (var jsonValue in jsonObject.GetNamedArray("ConnectedPositions", new JsonArray()))
            {
                obj.ConnectedPositions.Add(EnumParser.ToPositionType(jsonValue.GetString()));
            }

            obj.Status = new Dictionary <string, int[]>();

            var status = jsonObject.GetNamedObject("Status");

            foreach (var statusKey in status.Keys)
            {
                var arr  = status.GetNamedArray(statusKey, new JsonArray());
                var item = new int[arr.Count];
                var i    = 0;
                foreach (var jsonValue in arr)
                {
                    item[i] = (int)jsonValue.GetNumber();
                    i++;
                }
                obj.Status[statusKey] = item;
            }

            return(obj);
        }