當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。