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


C# JArray.Cast方法代码示例

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


在下文中一共展示了JArray.Cast方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryParseCoordinate

 private bool TryParseCoordinate(JArray coordinates, out CoordinateInfo result)
 {
     if (coordinates != null && coordinates.Count > 1 && coordinates.All(x => x is JValue))
     {
         var vals = coordinates.Cast<JValue>().ToList();
         if (vals.All(x => x.Type == JTokenType.Float || x.Type == JTokenType.Integer))
         {
             result = new CoordinateInfo
             {
                 X = Convert.ToDouble(vals[0].Value),
                 Y = Convert.ToDouble(vals[1].Value),
                 Z = vals.Count > 2 ? Convert.ToDouble(vals[2].Value) : (double?)null,
                 M = vals.Count > 3 ? Convert.ToDouble(vals[3].Value) : (double?)null
             };
             return true;
         }
     }
     result = null;
     return false;
 }
开发者ID:s-innovations,项目名称:azure-table-storage-repository-pattern,代码行数:20,代码来源:GeoJsonReader.cs

示例2: ParseListListListPosition

            /// <summary>
            /// Helper function to parse a <see cref="List{T}"/> of <see cref="List{T}"/> of <see cref="List{T}"/> of <see cref="Position"/>.
            /// </summary>
            /// <param name="array">
            /// Get JSON from this.
            /// </param>
            /// <returns>
            /// The parsed JSON.
            /// </returns>
            /// <exception cref="ArgumentException">
            /// Unexpected JSON.
            /// </exception>
            public static List<List<List<Position>>> ParseListListListPosition(JArray array)
            {
                if (array.Cast<JArray>().Any(p => p.Cast<JArray>().Any(r => r.Cast<JArray>().Any(l => l.Count < 2))))
                {
                    throw new ArgumentException(
                    string.Format(
                    "Expected all points to have greater than two points, got {0} with zero and {1} with one",
                    array.Cast<JArray>().Sum(p => p.Cast<JArray>().Sum(r => r.Cast<JArray>().Count(l => l.Count == 0))),
                    array.Cast<JArray>().Sum(p => p.Cast<JArray>().Sum(r => r.Cast<JArray>().Count(l => l.Count == 1)))),
                    "array");
                }

                return array.Select(p => p.Select(r => r.Select(l => new Position { P1 = (double)l[0], P2 = (double)l[1] }).ToList()).ToList()).ToList();
            }
开发者ID:altaricka,项目名称:vDesign,代码行数:26,代码来源:DbGeographyGeoJsonConverter.cs

示例3: SetModelPropertyData

 public void SetModelPropertyData(JArray modelPropertyData)
 {
     InputParameters = modelPropertyData.Cast<JObject>().Where(inputParameter=>!(bool)inputParameter["IsResult"]).Select<JObject,EffectsInputParameterViewModel>(inputParameter =>
     {
         switch ((int) inputParameter["ParameterType"])
         {
             case 1:
                 // Integer
                 // todo: if both min and max are specified create slider input
                 if (inputParameter["Data"]["Min"] != null && inputParameter["Data"]["Max"] != null && !double.IsNaN((double)inputParameter["Data"]["Min"]) && !double.IsNaN((double)inputParameter["Data"]["Max"]))
                 {
                     return new EffectsRangeInputParameterViewModel() {Data = inputParameter};
                 }
                 else
                 {
                     return new EffectsDoubleInputParameterViewModel() {Data = inputParameter};
                 }
                 break;
             case 6:
                 // Chemical
                 return new EffectsChemicalInputParameterViewModel(){Data = inputParameter, ChemicalData = new JArray(Chemicals)};
             default:
                 return null;
         }
     }).Where(vm=>vm != null);
 }
开发者ID:TNOCS,项目名称:csTouch,代码行数:26,代码来源:EffectsModelSettingsViewModel.cs

示例4: ParseListPosition

            /// <summary>
            /// Helper function to parse a <see cref="List{T}"/> of <see cref="Position"/>.
            /// </summary>
            /// <param name="array">
            /// Get JSON from this.
            /// </param>
            /// <returns>
            /// The parsed JSON.
            /// </returns>
            /// <exception cref="ArgumentException">
            /// Unexpected JSON.
            /// </exception>
            public static List<Position> ParseListPosition(JArray array)
            {
                if (array.Cast<JArray>().Any(l => l.Count < 2))
                {
                    throw new ArgumentException(
                    string.Format(
                    "Expected all points to have greater than two points, got {0} with zero and {1} with one",
                    array.Cast<JArray>().Count(l => l.Count == 0),
                    array.Cast<JArray>().Count(l => l.Count == 1)),
                    "array");
                }

                return array.Select(l => new Position(l)).ToList();
            }
开发者ID:crazymouse0,项目名称:gis,代码行数:26,代码来源:DbGeometryConverter.cs

示例5: ParseArray

 public static UpdateInfo[] ParseArray(JArray jsonArray)
 {
     return jsonArray.Cast<JObject>().Select(jobject => new UpdateInfo(jobject)).ToArray();
 }
开发者ID:themehrdad,项目名称:NetTelebot,代码行数:4,代码来源:UpdateInfo.cs

示例6: DeserializeList

        /// <summary>
        /// 反序列化指定的数组为一个实体的列表。
        /// </summary>
        /// <param name="listType"></param>
        /// <param name="jArray"></param>
        /// <returns></returns>
        public EntityList DeserializeList(Type listType, JArray jArray)
        {
            var entityType = EntityMatrix.FindByList(listType).EntityType;
            var repo = RF.Find(entityType);

            //先从数据库中找出所有提供了 Id 的实体。
            var idList = jArray.Cast<JObject>().Select(item => TryGetId(item))
                .Where(id => id != null).ToArray();
            var list = repo.GetByIdList(idList);

            //依次反序列化数组中的实体:
            //如果有 Id,则在数据库中查询出的列表 list 中查找出对应的实体,然后反序列化值。否则,直接构造新实体。
            for (int i = 0, c = jArray.Count; i < c; i++)
            {
                var jEntity = jArray[i] as JObject;
                var child = FindOrCreate(list, jEntity);
                DeserializeProperties(jEntity, child);
            }

            return list;
        }
开发者ID:569550384,项目名称:Rafy,代码行数:27,代码来源:AggtDeserializer.cs

示例7: ParseArray

 internal static PhotoSizeInfo[] ParseArray(JArray jsonArray)
 {
     return jsonArray.Cast<JObject>().Select(jobject => new PhotoSizeInfo(jobject)).ToArray();
 }
开发者ID:themehrdad,项目名称:NetTelebot,代码行数:4,代码来源:PhotoSizeInfo.cs

示例8: ParseJson

            /// <inheritdoc/>
            public override void ParseJson(JArray array)
            {
                if (array.Cast<JArray>().Any(l => l.Count < 2))
                {
                    throw new ArgumentException(
                    string.Format(
                    "Expected all points to have greater than two points, got {0} with zero and {1} with one",
                    array.Cast<JArray>().Count(l => l.Count == 0),
                    array.Cast<JArray>().Count(l => l.Count == 1)),
                    "array");
                }

                this.Points = array.Cast<JArray>().Select(l => new Point { Position = new Position { P1 = (double)l[0], P2 = (double)l[1] } }).ToList();
            }
开发者ID:altaricka,项目名称:vDesign,代码行数:15,代码来源:DbGeographyGeoJsonConverter.cs


注:本文中的Newtonsoft.Json.Linq.JArray.Cast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。