當前位置: 首頁>>代碼示例>>C#>>正文


C# JObject.Remove方法代碼示例

本文整理匯總了C#中Newtonsoft.Json.Linq.JObject.Remove方法的典型用法代碼示例。如果您正苦於以下問題:C# JObject.Remove方法的具體用法?C# JObject.Remove怎麽用?C# JObject.Remove使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Newtonsoft.Json.Linq.JObject的用法示例。


在下文中一共展示了JObject.Remove方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CreateResource

        static IResource CreateResource(JObject jObj, Type resourceType)
        {
            // remove _links and _embedded so those don't try to deserialize, because we know they will fail
            JToken links;
            if (jObj.TryGetValue(HalLinksName, out links))
                jObj.Remove(HalLinksName);
            JToken embeddeds;
            if (jObj.TryGetValue(HalEmbeddedName, out embeddeds))
                jObj.Remove(HalEmbeddedName);

            // create value properties in base object
            var resource = jObj.ToObject(resourceType) as IResource;
            if (resource == null) return null;

            // links are named properties, where the name is Link.Rel and the value is the rest of Link
            if (links != null)
            {
                foreach (var rel in links.OfType<JProperty>())
                    CreateLinks(rel, resource);
                var self = resource.Links.SingleOrDefault(l => l.Rel == "self");
                if (self != null)
                    resource.Href = self.Href;
            }

            // embedded are named properties, where the name is the Rel, which needs to map to a Resource Type, and the value is the Resource
            // recursive
            if (embeddeds != null)
            {
                foreach (var prop in resourceType.GetProperties().Where(p => Representation.IsEmbeddedResourceType(p.PropertyType)))
                {
                    // expects embedded collection of resources is implemented as an IList on the Representation-derived class
                    if (typeof (IEnumerable<IResource>).IsAssignableFrom(prop.PropertyType))
                    {
                        var lst = prop.GetValue(resource) as IList;
                        if (lst == null)
                        {
                            lst = ConstructResource(prop.PropertyType) as IList ??
                                  Activator.CreateInstance(
                                      typeof (List<>).MakeGenericType(prop.PropertyType.GenericTypeArguments)) as IList;
                            if (lst == null) continue;
                            prop.SetValue(resource, lst);
                        }
                        if (prop.PropertyType.GenericTypeArguments != null &&
                            prop.PropertyType.GenericTypeArguments.Length > 0)
                            CreateEmbedded(embeddeds, prop.PropertyType.GenericTypeArguments[0],
                                newRes => lst.Add(newRes));
                    }
                    else
                    {
                        var prop1 = prop;
                        CreateEmbedded(embeddeds, prop.PropertyType, newRes => prop1.SetValue(resource, newRes));
                    }
                }
            }

            return resource;
        }
開發者ID:iremezoff,項目名稱:AspNet.Hal,代碼行數:57,代碼來源:ResourceConverter.cs

示例2: 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

示例3: Post

        public JObject Post(int userId, JObject json)
        {
            var user = DataContext.User.Get(userId);
            if (user == null)
                ThrowHttpResponse(HttpStatusCode.NotFound, "User not found!");

            var jsonClient = json["client"] as JObject;
            if (jsonClient == null)
                ThrowHttpResponse(HttpStatusCode.BadRequest, "The 'client' field is required!");
            json.Remove("client");

            var oauthGrant = Mapper.Map(json);
            oauthGrant.UserID = user.ID;
            oauthGrant.Client = MapClient(jsonClient);
            if (string.IsNullOrEmpty(oauthGrant.RedirectUri))
                ThrowHttpResponse(HttpStatusCode.BadRequest, "Missing required field: redirectUri");

            OAuth2Controller.RenewGrant(oauthGrant);
            Validate(oauthGrant);

            DataContext.AccessKey.Save(oauthGrant.AccessKey);
            DataContext.OAuthGrant.Save(oauthGrant);

            if (oauthGrant.Type == (int)OAuthGrantType.Code)
                oauthGrant.AccessKey = null; // do not disclose key in authorization code scenario

            return Mapper.Map(oauthGrant, oneWayOnly: true);
        }
開發者ID:bestpetrovich,項目名稱:devicehive-.net,代碼行數:28,代碼來源:OAuthGrantController.cs

示例4: OnPut

        public override void OnPut(string key, JObject document, JObject metadata, TransactionInformation transactionInformation)
        {
			if (VersioningContext.IsInVersioningContext)
				return;
			if (key.StartsWith("Raven/", StringComparison.InvariantCultureIgnoreCase))
				return;

			if (excludeByEntityName.Contains(metadata.Value<string>("Raven-Entity-Name")))
				return;

			if (metadata.Value<string>(RavenDocumentRevisionStatus) == "Historical")
				return;

			using(VersioningContext.Enter())
			{
				var copyMetadata = new JObject(metadata);
				copyMetadata[RavenDocumentRevisionStatus] = JToken.FromObject("Historical");
				copyMetadata.Remove(RavenDocumentRevision);
				var parentRevision = metadata.Value<string>(RavenDocumentRevision);
				if(parentRevision!=null)
				{
					copyMetadata[RavenDocumentParentRevision] = key + "/revisions/" + parentRevision;
					metadata[RavenDocumentParentRevision] = key + "/revisions/" + parentRevision;
				}

				PutResult newDoc = Database.Put(key + "/revisions/", null, document, copyMetadata,
											 transactionInformation);
				int revision = int.Parse(newDoc.Key.Split('/').Last());

				RemoveOldRevisions(key, revision, transactionInformation);

				metadata[RavenDocumentRevisionStatus] = JToken.FromObject("Current");
				metadata[RavenDocumentRevision] = JToken.FromObject(revision);
			}
        }
開發者ID:ajaishankar,項目名稱:ravendb,代碼行數:35,代碼來源:VersioningPutTrigger.cs

示例5: AddLookupData

        public static JObject AddLookupData(string environment, JObject o)
        {
            var props = o.Properties().ToList();
            foreach (var p in props)
            {
                foreach (var k in LookupIdIndex.Keys)
                {
                    if (p.Name == k && p.Value != null && p.Value.ToString() != string.Empty)
                    {
                        Table lookupTable = LookupIdIndex[k];

                        JObject lookupItem = Get(environment, lookupTable.Name, p.Value.ToString());

                        if (lookupItem != null)
                        {
                            if (lookupTable.LookupDescriptor != null)
                            {
                                o[lookupTable.Name] = lookupItem[lookupTable.LookupDescriptor];
                            }
                            else
                            {
                                o[lookupTable.Name] = lookupItem;
                            }

                            o.Remove(p.Name);
                        }
                    }
                }
            }

            return o;
        }
開發者ID:NGPVAN,項目名稱:dnorml,代碼行數:32,代碼來源:Cache.cs

示例6: PostFormat

        /// <summary>
        /// Removes the standard non configurable properties.
        /// </summary>
        public JObject PostFormat(JObject json, object value, Type type)
        {
            if (json == null)
                throw new ArgumentNullException(nameof(json));
            if (value == null)
                throw new ArgumentNullException(nameof(value));
            if (type == null)
                throw new ArgumentNullException(nameof(type));

            if (value is IIdentifier)
                json.Remove("id");

            if (value is IModified)
                json.Remove(new[] { "created_on", "modified_on" });

            return json;
        }
開發者ID:isbtech,項目名稱:CloudFlare.NET,代碼行數:20,代碼來源:StandardNonconfigurablePropertyFormatter.cs

示例7: setAutoComplite

 private void setAutoComplite()
 {
     JObject joContextKey = new JObject();
     joContextKey["SearchCode"] = "1";
     this.AutoComplit(ref joContextKey, "~/Tools/LandUse.asmx/GetCompletionList", this.txtFirst);
     joContextKey.Remove("SearchCode");
     joContextKey["SearchParams"] = new JRaw("function () {return UpdateContext();}");
     this.AutoComplit(ref joContextKey, "~/Tools/LandUse.asmx/GetCompletionList2", this.txtSecond);
 }
開發者ID:ranyaof,項目名稱:gismaster,代碼行數:9,代碼來源:Default2.aspx.cs

示例8: MigrateContent

        bool MigrateContent(JObject x)
        {
            if (x["Content"] is JObject)
            {
                // already converted
                return false;
            }

            var content = new Content();
            content.Title = x.Value<string>("Title");
            content.Body = x.Value<string>("Content");
            content.Format = (ContentFormat)x.Value<int>("Format");
            x.Remove("Title");
            x.Remove("Content");
            x.Remove("Format");
            x["Content"] = Session.Serializer.WriteFragment(content);
            return true;
        }
開發者ID:nicknystrom,項目名稱:AscendRewards,代碼行數:18,代碼來源:MigrateFrom0000.cs

示例9: RemoveCreatesNewJObjectWithPropertiesRemoved

        public void RemoveCreatesNewJObjectWithPropertiesRemoved()
        {
            JObject obj = new JObject() { { "prop1", "value1" }, { "prop2", "value2" } };
            JObject obj2 = obj.Remove(prop => prop.Name.Equals("prop1"));

            Assert.AreNotSame(obj, obj2);
            Assert.IsTrue(((IDictionary<string,JToken>)obj2).ContainsKey("prop2"));
            Assert.IsFalse(((IDictionary<string,JToken>)obj2).ContainsKey("prop1"));
        }
開發者ID:jlaanstra,項目名稱:azure-mobile-services,代碼行數:9,代碼來源:JObjectExtensionsTest.cs

示例10: FotoliaGetSearchResult

 public FotoliaGetSearchResult(JObject searchResultData)
 {
     Items = new List<FotoliaSearchResultItem>();
     TotalCount = searchResultData["nb_results"].ToObject<int>();
     searchResultData.Remove("nb_results");
     foreach (var item in searchResultData)
     {
         Items.Add(new FotoliaSearchResultItem(item));
     }
 }
開發者ID:vmaron,項目名稱:FotoliaSharp,代碼行數:10,代碼來源:FotoliaGetSearchResult.cs

示例11: Strip

        private static void Strip(JObject metadata)
        {
            var propertiesToRemove = new List<string>();

            foreach (var property in metadata.Properties())
            {
                if (property.Name.StartsWith("x_netkan"))
                {
                    propertiesToRemove.Add(property.Name);
                }
                else switch (property.Value.Type)
                {
                    case JTokenType.Object:
                        Strip((JObject)property.Value);
                        break;
                    case JTokenType.Array:
                        foreach (var element in ((JArray)property.Value).Where(i => i.Type == JTokenType.Object))
                        {
                            Strip((JObject)element);
                        }
                        break;
                }
            }

            foreach (var property in propertiesToRemove)
            {
                metadata.Remove(property);
            }

            if (metadata["$kref"] != null)
            {
                metadata.Remove("$kref");
            }

            if (metadata["$vref"] != null)
            {
                metadata.Remove("$vref");
            }
        }
開發者ID:CliftonMarien,項目名稱:CKAN,代碼行數:39,代碼來源:StripNetkanMetadataTransformer.cs

示例12: ParseSearchResult

        /// <summary>
        /// This method parses the search result because device's local DB can only handle strings shorter than 4000 characters.
        /// </summary>
        private void ParseSearchResult(JObject resultObj)
        {
            int removableItemIndex = 0;

            while (resultObj.ToString(Newtonsoft.Json.Formatting.None).Length > searchResultMaxLength)
            {
                resultObj.Remove(searchResultRemovableItems[removableItemIndex]);
                if (removableItemIndex < searchResultRemovableItems.Length)
                    removableItemIndex++;
                else
                    break;
            }
        }
開發者ID:WinToosa,項目名稱:mobilelogger,代碼行數:16,代碼來源:SearchDataHandler.cs

示例13: MergeTemplateStart

 private void MergeTemplateStart(JObject iTarget, JObject iTemplate, string iKnxReplace) {
     //evaluate template
     JProperty lTemplate = iTarget.Property("$template");
     //string lOldKnxReplace = "";
     if (lTemplate != null) {
         //JProperty lKnx = (lTemplate.Value as JObject).Property("knx");
         //if (lKnx != null) {
         //    lOldKnxReplace = gKnxReplace;
         //    gKnxReplace = lKnx.Value.ToString();
         //}
         JObject lTemplateObject = iTemplate.Properties().Last().Value as JObject;
         iTarget.Remove("$template");
         MergeTemplate(iTarget, lTemplateObject, iKnxReplace);
         //if (lKnx != null && lOldKnxReplace != "-/-/-") gKnxReplace = lOldKnxReplace;
     }
 }
開發者ID:ivan73,項目名稱:json,代碼行數:16,代碼來源:MergeTemplate.cs

示例14: MoveExtraExceptionProperties

        private void MoveExtraExceptionProperties(JObject doc, JObject extendedData = null) {
            if (doc == null)
                return;

            if (extendedData == null)
                extendedData = doc["Data"] as JObject;

            string json = extendedData != null && extendedData["__ExceptionInfo"] != null ? extendedData["__ExceptionInfo"].ToString() : null;
            if (String.IsNullOrEmpty(json))
                return;

            try {
                var extraProperties = JObject.Parse(json);
                foreach (var property in extraProperties.Properties())
                    doc.Add(property.Name, property.Value);
            } catch (Exception) {}

            extendedData.Remove("__ExceptionInfo");
        }
開發者ID:BookSwapSteve,項目名稱:Exceptionless,代碼行數:19,代碼來源:V2_EventUpgrade.cs

示例15: Sort

        private static void Sort(JObject jObject)
        {
            var props = jObject.Properties().ToList();

            foreach (var prop in props)
            {
                jObject.Remove(prop.Name);
            }

            foreach (var prop in props.OrderBy(p => p.Name))
            {
                jObject.Add(prop);

                if (prop.Value is JObject)
                {
                    Sort((JObject) prop.Value);
                }
            }
        }
開發者ID:borealwinter,項目名稱:simpl,代碼行數:19,代碼來源:JsonHelper.cs


注:本文中的Newtonsoft.Json.Linq.JObject.Remove方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。