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


C# JToken.SelectTokens方法代码示例

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


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

示例1: ConvertPesudoTypes

        public static JToken ConvertPesudoTypes(JToken data, FormatOptions fmt)
        {
            var reqlTypes = data.SelectTokens("$..$reql_type$").ToList();

            foreach ( var typeToken in reqlTypes )
            {
                var reqlType = typeToken.Value<string>();
                //JObject -> JProerty -> JVaule:$reql_type$, go backup the chain.
                var pesudoObject = typeToken.Parent.Parent as JObject;

                JToken convertedValue = null;
                if( reqlType == Time )
                {
                    if( fmt.RawTime )
                        continue;
                    convertedValue = new JValue(GetTime(pesudoObject));
                }
                else if( reqlType == GroupedData )
                {
                    if( fmt.RawGroups )
                        continue;
                    convertedValue = new JValue(GetGrouped(pesudoObject));
                }
                else if( reqlType == Binary )
                {
                    if( fmt.RawBinary )
                        continue;
                    convertedValue = new JArray(GetBinary(pesudoObject));
                }

                pesudoObject.Replace(convertedValue);
            }

            return data;
        }
开发者ID:cadabloom,项目名称:RethinkDb.Driver,代码行数:35,代码来源:Converter3.cs

示例2: SelectChildren

        /// <summary/>
        private static IEnumerable<JObject>     SelectChildren(JToken root, string path)
        {
            // JObject children (only)
            //   As JObject(fields) have a clear mapping to Row(columns) as opposed to JArray (positional) or JValue(scalar)
            //  Note: 
            //   We ignore other types (as opposed to fail fast) since JSON supports heterogeneous (schema)
            //   We support the values that can be mapped, without failing all of them if one of happens to not be an Object.

            // Path specified
            if(!string.IsNullOrEmpty(path))
            {
                return root.SelectTokens(path).OfType<JObject>();
            }
            
            // Single JObject
            var o = root as JObject;
            if(o != null)
            {
                return new []{o};
            }

            // Multiple JObjects
            return root.Children().OfType<JObject>();
        }
开发者ID:hughwasos,项目名称:usql,代码行数:25,代码来源:JsonExtractor.cs

示例3: Remove

        /// <summary>
        /// Removes tokens from this JSON token using a collection of patterns.
        /// This naive algorithm marks all the affected leaves every time
        /// a pattern is evaluated.
        /// </summary>
        public void Remove(JToken root, PatternCollection patterns)
        {
            var leaves = ((JContainer) root).DescendantsAndSelf().OfType<JValue>().ToArray();
            var exclusionDictionary = leaves.ToDictionary(GetId, x => false);

            foreach (var pattern in patterns)
                foreach (var matched in root.SelectTokens(pattern.Expression))
                    foreach (var leaf in FindLeaves(matched))
                        exclusionDictionary[GetId(leaf)] = !pattern.IsNegated;

            var toRemove = leaves.Where(x => exclusionDictionary[GetId(x)]);
            var queue = new Queue<JToken>(toRemove);

            while (queue.IsNotEmpty())
            {
                var toHandle = queue.Dequeue();
                if (!toHandle.HasValues)
                {
                    var parent = toHandle.RemoveFromParent();
                    if (parent != null)
                        queue.Enqueue(parent);
                }
            }
        }
开发者ID:pgolebiowski,项目名称:onism-cldr,代码行数:29,代码来源:NaiveTokenRemover.cs

示例4: ParseResults

 public List<MovieSearchResult> ParseResults(JToken token)
 {
     var items = new JArray(token.SelectTokens("[*].results").Cast<JArray>().SelectMany(a => a));
     var result = items.ToObject<List<MovieSearchResult>>();
     return result;
 }
开发者ID:craigrs84,项目名称:PvrScraper,代码行数:6,代码来源:TmDbSync.cs

示例5: ParseMovies

 public List<Movie> ParseMovies(JToken token)
 {
     int i = 0;
     var items = new JArray(token.SelectTokens("[*].results").Cast<JArray>().SelectMany(a => a));
     var result = items.ToObject<List<Movie>>();
     result.ForEach(a => a.Source = items[i++].ToString(Formatting.Indented));
     return result;
 }
开发者ID:craigrs84,项目名称:PvrScraper,代码行数:8,代码来源:TmDbSync.cs

示例6: ConvertPseudoTypes

        /// <summary>
        /// Method for converting pseudo types in JToken (JObjects)
        /// </summary>
        public static void ConvertPseudoTypes(JToken data, FormatOptions fmt)
        {
            var reqlTypes = data.SelectTokens("$..$reql_type$").ToList();

            foreach (var typeToken in reqlTypes)
            {
                var reqlType = typeToken.Value<string>();
                //JObject -> JProerty -> JVaule:$reql_type$, go backup the chain.
                var pesudoObject = typeToken.Parent.Parent as JObject;

                JToken convertedValue = null;
                if (reqlType == Time)
                {
                    if (fmt.RawTime)
                        continue;
                    convertedValue = new JValue(GetTime(pesudoObject));
                }
                else if (reqlType == GroupedData)
                {
                    if (fmt.RawGroups)
                        continue;
                    convertedValue = GetGrouped(pesudoObject);
                }
                else if (reqlType == Binary)
                {
                    if (fmt.RawBinary)
                        continue;
                    convertedValue = new JValue(GetBinary(pesudoObject));
                }
                else if (reqlType == Geometry)
                {
                    // Nothing specific here
                    continue;
                }
                else
                {
                    // Just leave unknown pseudo-types alone
                    continue;
                }

                pesudoObject.Replace(convertedValue);
            }
        }
开发者ID:fjsnogueira,项目名称:RethinkDb.Driver,代码行数:46,代码来源:Converter.cs


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