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


C# JObject.Children方法代码示例

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


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

示例1: FlattenTitleProperty

 private static void FlattenTitleProperty(JObject o, SlackAttachment attachment)
 {
     var titleProp = o.Children<JProperty>().FirstOrDefault(z => z.Name == "title");
     if (titleProp != null && attachment.Title != null)
     {
         titleProp.Value = attachment.Title.Name;
         if (attachment.Title.Link != null)
             titleProp.AddAfterSelf(new JProperty("title_link", attachment.Title.Link.OriginalString));
     }
 }
开发者ID:louisukiri,项目名称:SlackClient,代码行数:10,代码来源:SlackAttachmentConverter.cs

示例2: ReadMultipleFromJObject

 //returns: <marketID,OrderBook>
 public static Dictionary<Int64, OrderBook> ReadMultipleFromJObject(JObject o)
 {
     Dictionary<Int64,OrderBook> markets = new Dictionary<Int64,OrderBook>();
     foreach (var market in o.Children())
     {
         Int64 marketID = market.First().Value<Int64>("marketid");
         markets.Add(marketID,ReadFromJObject(market.First() as JObject,marketID));
     }
     return markets;
 }
开发者ID:RickardPettersson,项目名称:CryptsyAPICS,代码行数:11,代码来源:OrderBook.cs

示例3: Remove

    public void Remove()
    {
      JObject o = new JObject();
      o.Add("PropertyNameValue", new JValue(1));
      Assert.AreEqual(1, o.Children().Count());

      Assert.AreEqual(false, o.Remove("sdf"));
      Assert.AreEqual(false, o.Remove(null));
      Assert.AreEqual(true, o.Remove("PropertyNameValue"));

      Assert.AreEqual(0, o.Children().Count());
    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:12,代码来源:JObjectTests.cs

示例4: MustacheTest

            public MustacheTest(string specName, JToken test, JObject stronglyTypedExamples)
            {
                this.SpecName = specName;
                this.SanitizedName = Sanitize(test["name"].ToString());
                this.test = test;
                this.Template = StripReservedWords(test["template"].ToString());

                if (stronglyTypedExamples.Children().Any())
                {
                    if (stronglyTypedExamples[SanitizedName] != null)
                        this.Example =
                            new JavaScriptSerializer().DeserializeObject(stronglyTypedExamples[SanitizedName].ToString());
                    else
                        this.Example = new object();

                    var stronglyTypedClass = Assembly.GetExecutingAssembly().GetType(
                            Generate_Classes_from_JSON.FullTestClassName(specName, this.SanitizedName));
                    if (stronglyTypedClass != null)
                    {
                        this.StronglyTypedExample = Activator.CreateInstance(
                            stronglyTypedClass,
                            stronglyTypedExamples[this.SanitizedName]);
                    }
                }
                else
                {
                    this.StronglyTypedExample = new object();
                    this.Example = new object();
                }
            }
开发者ID:reicheltp,项目名称:Nustache,代码行数:30,代码来源:MustacheSpec.cs

示例5: TraverseObject

        private void TraverseObject(JObject instance)
        {

            foreach (JProperty property in instance.Children().Where(t => t is JProperty).OfType<JProperty>())
            {
                ProcessElement(property.Value);
            }
        }
开发者ID:jarlef,项目名称:Bifrost,代码行数:8,代码来源:JsonInterceptor.cs

示例6: ExpandField

 protected string ExpandField(string fieldName, JObject json)
 {
     foreach (var token in json.Children())
     {
         string replaceString = "%{" + token.Path + "}";
         fieldName = fieldName.Replace(replaceString, json[token.Path].ToString());
     }
     return fieldName;
 }
开发者ID:schmidt4brains,项目名称:TimberWinR,代码行数:9,代码来源:PlainCodec.cs

示例7: ParseJsonToStructData

        /// <summary>
        /// json数据包装成数据结构
        /// </summary>
        /// <param name="rootData">json数据</param>
        /// <returns></returns>
        IServerResponseData ParseJsonToStructData(JObject rootData)
        {
            IServerResponseData objServerResponseData = new ServerResponseData();

            JProperty jPropertyCode = null;
            JProperty jPropertyMsg = null;
            JProperty jPropertyUpdate = null;
            JProperty jPropertyGmt = null;
            foreach (JProperty jPropertyRootItem in rootData.Children())
            {
                if (SERVER_RESPONSE_CODE == jPropertyRootItem.Name)
                {
                    jPropertyCode = jPropertyRootItem;
                }
                else if (SERVER_RESPONSE_MSG == jPropertyRootItem.Name)
                {
                    jPropertyMsg = jPropertyRootItem;
                }
                else if (SERVER_RESPONSE_UPDATE == jPropertyRootItem.Name)
                {
                    jPropertyUpdate = jPropertyRootItem;
                }
                else if (SERVER_RESPONSE_GMT == jPropertyRootItem.Name)
                {
                    jPropertyGmt = jPropertyRootItem;
                }
            }

            if (jPropertyCode != null)
            {
                objServerResponseData.code = ParseCode(jPropertyCode);
                objServerResponseData.serverTime = long.Parse(jPropertyGmt.Value.ToString());
                if (0 == objServerResponseData.code)
                {
                    if (jPropertyMsg != null)
                    {
                        objServerResponseData.msgListData = ParseMsg(jPropertyMsg);
                    }

                    if (jPropertyUpdate != null)
                    {
                        objServerResponseData.updateListData = ParseUpdate(jPropertyUpdate);
                    }

                }
                else
                {
                    if (jPropertyMsg != null)
                    {
                        objServerResponseData.errMsg = jPropertyMsg.Value.ToString();
                    }
                }
            }

            return objServerResponseData;
        }
开发者ID:dengswing,项目名称:network,代码行数:61,代码来源:JsonDataManager.cs

示例8: GetAnnotationsFromResponsePayload

        /// <summary>
        /// Gets all the annotations from the response payload.
        /// </summary>
        /// <param name="jObj">The response payload.</param>
        /// <param name="version">The version of the odata service.</param>
        /// <param name="type">The annotation type.</param>
        /// <param name="annotations">Stores all the annotation which were got from the response payload.</param>
        public static void GetAnnotationsFromResponsePayload(JObject jObj, ODataVersion version, AnnotationType type, ref List<JProperty> annotations)
        {
            if (jObj != null && annotations != null)
            {
                var jProps = jObj.Children();

                foreach (JProperty jProp in jProps)
                {
                    if (jProp.Value.Type == JTokenType.Object)
                    {
                        GetAnnotationsFromResponsePayload((JObject)jProp.Value, version, type, ref annotations);
                    }
                    else if (jProp.Value.Type == JTokenType.Array)
                    {
                        var objs = jProp.Value.Children();

                        foreach (var obj in objs)
                        {
                            if (typeof(JObject) == obj.GetType())
                            {
                                GetAnnotationsFromResponsePayload((JObject)obj, version, type, ref annotations);
                            }
                        }
                    }
                    else
                    {
                        // If the property's name contains dot(.), it will indicate that this property is an annotation.
                        if (jProp.Name.Contains("."))
                        {
                            switch (type)
                            {
                                default:
                                case AnnotationType.All:
                                    annotations.Add(jProp);
                                    break;
                                case AnnotationType.ArrayOrPrimitive:
                                    if (version == ODataVersion.V4 ? !jProp.Name.StartsWith("@") : jProp.Name.Contains("@"))
                                    {
                                        annotations.Add(jProp);
                                    }
                                    break;
                                case AnnotationType.Object:
                                    if (version == ODataVersion.V4 ? jProp.Name.StartsWith("@") : !jProp.Name.Contains("@"))
                                    {
                                        annotations.Add(jProp);
                                    }
                                    break;
                            }

                        }
                    }
                }
            }
        }
开发者ID:congysu,项目名称:ValidationTool,代码行数:61,代码来源:JsonParserHelper.cs

示例9: FlattenAuthorProperty

 private static void FlattenAuthorProperty(JObject o, SlackAttachment attachment)
 {
     var authorProp = o.Children<JProperty>().FirstOrDefault(z => z.Name == "author");
     if (authorProp != null && attachment.Author != null)
     {
         authorProp.AddAfterSelf(new JProperty("author_name", attachment.Author.Name));
         authorProp.AddAfterSelf(new JProperty("author_link", attachment.Author.Link));
         authorProp.AddAfterSelf(new JProperty("author_icon", attachment.Author.Icon));
         authorProp.Remove();
     }
 }
开发者ID:louisukiri,项目名称:SlackClient,代码行数:11,代码来源:SlackAttachmentConverter.cs

示例10: ValidateValues

 /// <summary>
 /// The validate values.
 /// </summary>
 /// <param name="controls">
 /// The controls.
 /// </param>
 /// <param name="data">
 /// The data.
 /// </param>
 /// <param name="errorList">
 /// The errorList.
 /// </param>
 private static void ValidateValues(JArray controls, JObject data, List<ValidationError> errorList)
 {
     foreach (JObject child in controls.OfType<JObject>())
     {
         IDynamicControl control = BaseControl.CreateControl(child);
         IDynamicValueControl valueControl = control as IDynamicValueControl;
         JProperty dataValue = null;
         if (valueControl != null)
         {
             dataValue = data.Children<JProperty>().FirstOrDefault(p => p.Name == child.Value<string>("name"));
             if (dataValue != null)
             {
                 JObject dataObject = dataValue.First as JObject;
                 if (dataObject != null)
                 {
                     JObject roles = child["checkedRoles"] as JObject;
                     if (roles != null)
                     {
                         if (roles.Value<bool>("required") && string.IsNullOrEmpty(dataObject.Value<string>("value")))
                         {
                             errorList.Add(new RequiredDataError(child.Value<string>("name")));
                         }
                     }
                     dataObject.Add(new JProperty("checked", true));
                 }
             }
             else
             {
                 errorList.Add(new MissingDataError(child.Value<string>("name")));
             }
         }
         IDynamicParentControl parentControl = control as IDynamicParentControl;
         if (parentControl != null)
         {
             JArray children = child.Value<JArray>("childs");
             if (children != null)
             {
                 JObject anyChildren = children.OfType<JObject>().FirstOrDefault(c => c.Value<string>("key") == "any");
                 if (anyChildren != null)
                 {
                     ValidateValues(anyChildren.Value<JArray>("controls"), data, errorList);
                 }
                 if (valueControl != null && dataValue != null)
                 {
                     JObject valueChildren = children.OfType<JObject>().FirstOrDefault(c => c.Value<string>("key") == dataValue.First.Value<string>("value"));
                     if (valueChildren != null)
                     {
                         ValidateValues(valueChildren.Value<JArray>("controls"), data, errorList);
                     }
                 }
             }
         }
     }
 }
开发者ID:UCASoft,项目名称:DynamicControls,代码行数:66,代码来源:DynamicValidator.cs

示例11: DictionaryItemShouldSet

    public void DictionaryItemShouldSet()
    {
      JObject o = new JObject();
      o["PropertyNameValue"] = new JValue(1);
      Assert.AreEqual(1, o.Children().Count());

      JToken t;
      Assert.AreEqual(true, o.TryGetValue("PropertyNameValue", out t));
      Assert.AreEqual(true, JToken.DeepEquals(new JValue(1), t));

      o["PropertyNameValue"] = new JValue(2);
      Assert.AreEqual(1, o.Children().Count());

      Assert.AreEqual(true, o.TryGetValue("PropertyNameValue", out t));
      Assert.AreEqual(true, JToken.DeepEquals(new JValue(2), t));

      o["PropertyNameValue"] = null;
      Assert.AreEqual(1, o.Children().Count());

      Assert.AreEqual(true, o.TryGetValue("PropertyNameValue", out t));
      Assert.AreEqual(true, JToken.DeepEquals(new JValue((object)null), t));
    }
开发者ID:pvasek,项目名称:Newtonsoft.Json,代码行数:22,代码来源:JObjectTests.cs

示例12: GenericCollectionRemove

    public void GenericCollectionRemove()
    {
      JValue v = new JValue(1);
      JObject o = new JObject();
      o.Add("PropertyNameValue", v);
      Assert.AreEqual(1, o.Children().Count());

      Assert.AreEqual(false, ((ICollection<KeyValuePair<string, JToken>>)o).Remove(new KeyValuePair<string, JToken>("PropertyNameValue1", new JValue(1))));
      Assert.AreEqual(false, ((ICollection<KeyValuePair<string, JToken>>)o).Remove(new KeyValuePair<string, JToken>("PropertyNameValue", new JValue(2))));
      Assert.AreEqual(false, ((ICollection<KeyValuePair<string, JToken>>)o).Remove(new KeyValuePair<string, JToken>("PropertyNameValue", new JValue(1))));
      Assert.AreEqual(true, ((ICollection<KeyValuePair<string, JToken>>)o).Remove(new KeyValuePair<string, JToken>("PropertyNameValue", v)));

      Assert.AreEqual(0, o.Children().Count());
    }
开发者ID:jonezy,项目名称:Epilogger-Collector,代码行数:14,代码来源:JObjectTests.cs

示例13: WriteSettingObject

		private void WriteSettingObject(JsonWriter writer, JObject obj)
		{
			writer.WriteStartObject();
			foreach (var property in obj.Children<JProperty>())
			{
				writer.WritePropertyName(property.Name);
				if (property.Value is JObject)
					this.WriteSettingObject(writer, property.Value as JObject);
				else
					writer.WriteValue(property.Value);
			}
			writer.WriteEndObject();

		}
开发者ID:strongant,项目名称:elasticsearch-net,代码行数:14,代码来源:IndexSettingsConverter.cs

示例14: TryGetValue

    public void TryGetValue()
    {
      JObject o = new JObject();
      o.Add("PropertyNameValue", new JValue(1));
      Assert.AreEqual(1, o.Children().Count());

      JToken t;
      Assert.AreEqual(false, o.TryGetValue("sdf", out t));
      Assert.AreEqual(null, t);

      Assert.AreEqual(false, o.TryGetValue(null, out t));
      Assert.AreEqual(null, t);

      Assert.AreEqual(true, o.TryGetValue("PropertyNameValue", out t));
      Assert.AreEqual(true, JToken.DeepEquals(new JValue(1), t));
    }
开发者ID:pvasek,项目名称:Newtonsoft.Json,代码行数:16,代码来源:JObjectTests.cs

示例15: LoadFromJObject

 public static void LoadFromJObject(this ContentItemHead contentItemHead_, JObject object_)
 {
     foreach (JToken token in object_.Children())
     {
         if (token is JProperty)
         {
             switch ((token as JProperty).Name.ToString())
             {
                 case "Title":
                     contentItemHead_.Title = (token as JProperty).Value.ToString();
                     break;
                 case "KeyWords":
                     contentItemHead_.KeyWords = (token as JProperty).Value.ToString();
                     break;
                 case "Description":
                     contentItemHead_.Description = (token as JProperty).Value.ToString();
                     break;
                 case "PageMetaTags":
                     contentItemHead_.PageMetaTags = (token as JProperty).Value.ToString();
                     break;
             }
         }
     }
 }
开发者ID:ramkumar013,项目名称:ECMS,代码行数:24,代码来源:ECMSExtensions.cs


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