当前位置: 首页>>代码示例>>C#>>正文


C# JsonTextReader.ReadStringArray方法代码示例

本文整理汇总了C#中Newtonsoft.Json.JsonTextReader.ReadStringArray方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextReader.ReadStringArray方法的具体用法?C# JsonTextReader.ReadStringArray怎么用?C# JsonTextReader.ReadStringArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Newtonsoft.Json.JsonTextReader的用法示例。


在下文中一共展示了JsonTextReader.ReadStringArray方法的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.ReadStringArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。