當前位置: 首頁>>代碼示例>>C#>>正文


C# JsonTextReader.ReadIntArray方法代碼示例

本文整理匯總了C#中Newtonsoft.Json.JsonTextReader.ReadIntArray方法的典型用法代碼示例。如果您正苦於以下問題:C# JsonTextReader.ReadIntArray方法的具體用法?C# JsonTextReader.ReadIntArray怎麽用?C# JsonTextReader.ReadIntArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Newtonsoft.Json.JsonTextReader的用法示例。


在下文中一共展示了JsonTextReader.ReadIntArray方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Deserialize

        public static ServerInformation[] Deserialize(Stream stream) {
            var reader = new JsonTextReader(new StreamReader(stream));

            var response = new List<ServerInformation>(1200);
            var currentProperty = string.Empty;

            reader.MatchNext(JsonToken.StartArray);
            while (reader.IsMatchNext(JsonToken.StartObject)) {
                var entry = new ServerInformation();

                while (reader.Until(JsonToken.EndObject)) {
                    switch (reader.TokenType) {
                        case JsonToken.PropertyName:
                            currentProperty = reader.Value.ToString();
                            break;

                        case JsonToken.String:
                            switch (currentProperty) {
                                case "ip":
                                    entry.Ip = reader.Value.ToString();
                                    break;
                                case "name":
                                    entry.Name = reader.Value.ToString();
                                    break;
                                case "track":
                                    entry.TrackId = reader.Value.ToString();
                                    break;
                            }
                            break;

                        case JsonToken.Integer:
                            switch (currentProperty) {
                                case "port":
                                    entry.Port = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture);
                                    break;
                                case "cport":
                                    entry.PortC = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture);
                                    break;
                                case "tport":
                                    entry.PortT = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture);
                                    break;
                                case "clients":
                                    entry.Clients = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture);
                                    break;
                                case "maxclients":
                                    entry.Capacity = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture);
                                    break;
                                case "timeofday":
                                    entry.Time = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture);
                                    break;
                                case "session":
                                    entry.Session = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture);
                                    break;
                                case "timeleft":
                                    entry.TimeLeft = long.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture);
                                    break;
                                case "timestamp":
                                    entry.Timestamp = long.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture);
                                    break;
                                case "lastupdate":
                                    entry.LastUpdate = long.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture);
                                    break;
                            }
                            break;

                        case JsonToken.Boolean:
                            switch (currentProperty) {
                                case "pass":
                                    entry.Password = bool.Parse(reader.Value.ToString());
                                    break;
                                case "pickup":
                                    entry.PickUp = bool.Parse(reader.Value.ToString());
                                    break;
                                case "l":
                                    entry.L = bool.Parse(reader.Value.ToString());
                                    break;
                            }
                            break;

                        case JsonToken.StartArray:
                            switch (currentProperty) {
                                case "cars":
                                    entry.CarIds = reader.ReadStringArray(1);
                                    break;
                                case "sessiontypes":
                                    entry.SessionTypes = reader.ReadIntArray(1);
                                    break;
                                case "durations":
                                    entry.Durations = reader.ReadLongArray(1);
                                    break;
                                case "country":
                                    entry.Country = reader.ReadStringArray(2);
                                    break;
                                default:
                                    while (reader.Until(JsonToken.EndArray)) { }
                                    break;
                            }
                            break;

                        default:
//.........這裏部分代碼省略.........
開發者ID:gro-ove,項目名稱:actools,代碼行數:101,代碼來源:ServerInformation.cs


注:本文中的Newtonsoft.Json.JsonTextReader.ReadIntArray方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。