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


C# JObject.Value方法代碼示例

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


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

示例1: TryParseDeploymentInfo

        // { 
        //   'format':'basic'
        //   'url':'http://host/repository',
        //   'is_hg':true // optional
        // }
        public override DeployAction TryParseDeploymentInfo(HttpRequestBase request, JObject payload, string targetBranch, out DeploymentInfo deploymentInfo)
        {
            deploymentInfo = null;
            if (!String.Equals(payload.Value<string>("format"), "basic", StringComparison.OrdinalIgnoreCase))
            {
                return DeployAction.UnknownPayload;
            }

            string url = payload.Value<string>("url");
            if (String.IsNullOrEmpty(url))
            {
                return DeployAction.UnknownPayload;
            }

            string scm = payload.Value<string>("scm");
            bool is_hg;
            if (String.IsNullOrEmpty(scm))
            {
                // SSH [email protected] vs [email protected]
                is_hg = url.StartsWith("[email protected]", StringComparison.OrdinalIgnoreCase);
            }
            else
            {
                is_hg = String.Equals(scm, "hg", StringComparison.OrdinalIgnoreCase);
            }

            deploymentInfo = new DeploymentInfo();
            deploymentInfo.RepositoryUrl = url;
            deploymentInfo.RepositoryType = is_hg ? RepositoryType.Mercurial : RepositoryType.Git;
            deploymentInfo.Deployer = GetDeployerFromUrl(url);
            deploymentInfo.TargetChangeset = DeploymentManager.CreateTemporaryChangeSet(message: "Fetch from " + url);

            return DeployAction.ProcessDeployment;
        }
開發者ID:40a,項目名稱:kudu,代碼行數:39,代碼來源:GenericHandler.cs

示例2: Deserialize

        public object Deserialize(JObject obj, JsonSerializer serializer)
        {
            if (obj == null) return null;

            var customField = new IssueCustomField
            {
                Id = obj.Value<int>(RedmineKeys.ID),
                Name = obj.Value<string>(RedmineKeys.NAME),
                Multiple = obj.Value<bool>(RedmineKeys.MULTIPLE)
            };

            var val = obj.Value<object>(RedmineKeys.VALUE);
            var items = serializer.Deserialize(new JTokenReader(val.ToString()), typeof(List<CustomFieldValue>)) as List<CustomFieldValue>;

            customField.Values = items;

            if (items == null) return customField;
            if (customField.Values == null) customField.Values = new List<CustomFieldValue>();

            var list = val as ArrayList;

            if (list != null)
            {
                foreach (string value in list)
                {
                    customField.Values.Add(new CustomFieldValue {Info = value});
                }
            }
            else
            {
                customField.Values.Add(new CustomFieldValue {Info = val as string});
            }

            return customField;
        }
開發者ID:Jopie64,項目名稱:redmine-net-api,代碼行數:35,代碼來源:IssueCustomFieldConverter.cs

示例3: GetDeploymentInfo

        protected override GitDeploymentInfo GetDeploymentInfo(HttpRequestBase request, JObject payload, string targetBranch)
        {
            var info = base.GetDeploymentInfo(request, payload, targetBranch);

            if (info == null)
            {
                return null;
            }

            // CodebaseHq format, see http://support.codebasehq.com/kb/howtos/repository-push-commit-notifications
            var repository = payload.Value<JObject>("repository");
            var urls = repository.Value<JObject>("clone_urls");
            var isPrivate = repository.Value<bool>("private");
            info.NewRef = payload.Value<string>("after");

            if (isPrivate)
            {
                info.RepositoryUrl = urls.Value<string>("ssh");
            }
            else
            {
                // use http clone url if it's a public repo
                info.RepositoryUrl = urls.Value<string>("http");                
            }

            return info;
        }
開發者ID:40a,項目名稱:kudu,代碼行數:27,代碼來源:CodebaseHqHandler.cs

示例4: MigrateAvailability

        bool MigrateAvailability(JObject x)
        {
            // determine our mode
            var a = new Availability();
            var availableToPublic = x.Value<bool>("AvailableToPublic ");
            var availableToAll = x.Value<bool>("AvailableToAllUsers");
            a.Mode = availableToPublic
                ? AvailabilityMode.AvailableToPublic
                : availableToAll 
                    ? AvailabilityMode.AvailableToAllUsers
                    : AvailabilityMode.AvailableOnlyTo;
            
            // copy users & groups arrays if there's any reason to
            if (AvailabilityMode.AvailableOnlyTo == a.Mode)
            {
                var users = x["Users"] as JArray;
                if (null != users)
                {
                    a.Users = users.Select(y => y.Value<string>()).ToArray();
                }
                var groups = x["Groups"] as JArray;
                if (null != groups)
                {
                    a.Groups = groups.Select(y => y.Value<string>()).ToArray();
                }
            }

            x["Availability"] = Session.Serializer.WriteFragment(a);
            return true;
        }
開發者ID:nicknystrom,項目名稱:AscendRewards,代碼行數:30,代碼來源:MigrateFrom0000.cs

示例5: RenewAccessToken

		void RenewAccessToken()
		{
			var postData = new StringBuilder();

			postData.AppendFormat("{0}={1}&", "grant_type", "client_credentials");
			postData.AppendFormat("{0}={1}&", "client_id", HttpUtility.UrlEncode(this.channelSettings.PackageSecurityIdentifier));
			postData.AppendFormat("{0}={1}&", "client_secret", HttpUtility.UrlEncode(this.channelSettings.ClientSecret));
			postData.AppendFormat("{0}={1}", "scope", "notify.windows.com");
			
			var wc = new WebClient();
			wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

			var response = string.Empty;

			response = wc.UploadString("https://login.live.com/accesstoken.srf", "POST", postData.ToString()); 

			var json = new JObject();

			try { json = JObject.Parse(response); }
			catch { }

			var accessToken = json.Value<string>("access_token");
			var tokenType = json.Value<string>("token_type");

			if (!string.IsNullOrEmpty(accessToken) && !string.IsNullOrEmpty(tokenType))
			{
				this.AccessToken = accessToken;
				this.TokenType = tokenType;
			}
			else
			{
				throw new UnauthorizedAccessException("Could not retrieve access token for the supplied Package Security Identifier (SID) and client secret");
			}
		}
開發者ID:StrangerMosr,項目名稱:PushSharp,代碼行數:34,代碼來源:WindowsPushChannel.cs

示例6: Auth

        public void Auth(JObject authData)
        {
            string key;
            User user;

            if(authData == null)
            {
                key = AuthProcessor.GenerateKey();
                user = AuthProcessor.NewAuthUser(key);
            }
            else
            {
                key = authData.Value<string>("key");
                user = AuthProcessor.GetUser(authData.Value<int>("id"));

                if (user == null || user.Key != key) //비정상 계정으로 판단하고 새로운 계정을 발급
                {
                    user = AuthProcessor.NewAuthUser(key);
                }

                user.Key = AuthProcessor.GenerateKey();
                user.Save();
            }

            _id = user.Id;

            //유저에게 바뀐 정보를 전송
            var obj = new JObject();
            obj.Add("type", "auth_data");
            obj.Add("id", user.Id);
            obj.Add("key", user.Key);
            _channel.SendMessage(obj);
        }
開發者ID:shlee322,項目名稱:Netronics,代碼行數:33,代碼來源:Client.cs

示例7: GetPatternsCollection

        public static IEnumerable<string> GetPatternsCollection(JObject rawProject,
                                                                string projectDirectory,
                                                                string projectFilePath,
                                                                string propertyName,
                                                                IEnumerable<string> defaultPatterns = null,
                                                                bool literalPath = false)
        {
            defaultPatterns = defaultPatterns ?? Enumerable.Empty<string>();

            try
            {
                JToken propertyNameToken;
                if (!rawProject.TryGetValue(propertyName, out propertyNameToken))
                {
                    return CreateCollection(projectDirectory, propertyName, defaultPatterns, literalPath);
                }

                if (propertyNameToken.Type == JTokenType.String)
                {
                    return CreateCollection(projectDirectory, propertyName, new string[] { propertyNameToken.Value<string>() }, literalPath);
                }

                if (propertyNameToken.Type == JTokenType.Array)
                {
                    var valuesInArray = propertyNameToken.Values<string>();
                    return CreateCollection(projectDirectory, propertyName, valuesInArray.Select(s => s.ToString()), literalPath);
                }
            }
            catch (Exception ex)
            {
                throw FileFormatException.Create(ex, rawProject.Value<JToken>(propertyName), projectFilePath);
            }

            throw FileFormatException.Create("Value must be either string or array.", rawProject.Value<JToken>(propertyName), projectFilePath);
        }
開發者ID:krwq,項目名稱:cli,代碼行數:35,代碼來源:PatternsCollectionHelper.cs

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

示例9: FileQuote

 internal FileQuote(JObject obj)
     : base(obj)
 {
     Body = obj.Value<string>("body");
     Title = obj.Value<string>("title");
     Identifier = obj.Value<string>("identifier");
 }
開發者ID:kevinkuszyk,項目名稱:gengo-dotnet,代碼行數:7,代碼來源:Quote.cs

示例10: ParserMatches

        protected virtual bool ParserMatches(HttpRequestBase request, JObject payload, string targetBranch)
        {
            JObject repository = payload.Value<JObject>("repository");
            if (repository == null)
            {
                return false;
            }

            // The format of ref is refs/something/something else
            // e.g. refs/head/master or refs/head/foo/bar
            string branch = payload.Value<string>("ref");

            if (String.IsNullOrEmpty(branch) || !branch.StartsWith("refs/", StringComparison.OrdinalIgnoreCase))
            {
                return false;
            }
            else
            {
                // Extract the name from refs/head/master notation.
                int secondSlashIndex = branch.IndexOf('/', 5);
                branch = branch.Substring(secondSlashIndex + 1);
                if (!branch.Equals(targetBranch, StringComparison.OrdinalIgnoreCase))
                {
                    return false;
                }
            }
            return true;
        }
開發者ID:projectkudu,項目名稱:kudu,代碼行數:28,代碼來源:GitHubCompatHandler.cs

示例11: CreateFromJObject

        public static Ticker CreateFromJObject(JObject o)
        {
            if (o == null)
            {
                return null;
            }

            decimal highestBid = 0m, lowestAsk = 0m;

            var sellOrders = o["sellorders"] as JArray;
            if (sellOrders != null)
            {
                lowestAsk = sellOrders.Min(s => s.Value<decimal>("price"));
            }
            var buyOrders = o["buyorders"] as JArray;
            if (buyOrders != null)
            {
                highestBid = buyOrders.Max(s => s.Value<decimal>("price"));
            }


            var tick = new Ticker()
            {
                Bid = highestBid,
                Ask = lowestAsk,
                Volume = o.Value<decimal>("volume"),
                High = o.Value<decimal>("24hhigh"),
                Low = o.Value<decimal>("24hlow"),
                Last = o.Value<decimal>("lasttradeprice")
            };

            return tick;
        }
開發者ID:erdincay,項目名稱:CoinTNet,代碼行數:33,代碼來源:Ticker.cs

示例12: ExecuteCommand

        public HttpResponseMessage ExecuteCommand(JObject input)
        {
            if (input == null)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            string command = input.Value<string>("command");
            string workingDirectory = input.Value<string>("dir");
            using (_tracer.Step("Executing " + command, new Dictionary<string, string> { { "CWD", workingDirectory } }))
            {
                try
                {
                    CommandResult result = _commandExecutor.ExecuteCommand(command, workingDirectory);
                    return Request.CreateResponse(HttpStatusCode.OK, result);
                }
                catch (CommandLineException ex)
                {
                    _tracer.TraceError(ex);
                    return Request.CreateResponse(HttpStatusCode.OK, new CommandResult { Error = ex.Error, ExitCode = ex.ExitCode });
                }
                catch (Exception ex)
                {
                    _tracer.TraceError(ex);
                    return Request.CreateResponse(HttpStatusCode.OK, new CommandResult { Error = ex.ToString(), ExitCode = -1 });
                }
            }
        }
開發者ID:40a,項目名稱:kudu,代碼行數:28,代碼來源:CommandController.cs

示例13: Statement

        public Statement(JObject jobj) : base(jobj) {
            if (jobj["id"] != null)
            {
                id = new Guid(jobj.Value<String>("id"));
            }
            if (jobj["stored"] != null)
            {
                stored = jobj.Value<DateTime>("stored");
            }
            if (jobj["authority"] != null)
            {
                authority = (Agent)jobj.Value<JObject>("authority");
            }
            if (jobj["version"] != null)
            {
                version = (TCAPIVersion)jobj.Value<String>("version");
            }

            //
            // handle SubStatement as target which isn't provided by StatementBase
            // because SubStatements are not allowed to nest
            //
            if (jobj["object"] != null && (String)jobj["object"]["objectType"] == SubStatement.OBJECT_TYPE)
            {
                target = (SubStatement)jobj.Value<JObject>("object");
            }
        }
開發者ID:rmabraham,項目名稱:TinCan.NET,代碼行數:27,代碼來源:Statement.cs

示例14: ParseOrderBook

        /// <summary>
        /// Parse market depth data (a paired list of bids and asks)
        /// </summary>
        /// <param name="depthJson"></param>
        /// <returns></returns>
        public static Book ParseOrderBook(JObject depthJson)
        {
            List<MarketDepth> asks = depthJson.Value<JArray>("asks").Select(depth => ParseMarketDepthEntry(depth)).ToList();
            List<MarketDepth> bids = depthJson.Value<JArray>("bids").Select(depth => ParseMarketDepthEntry(depth)).ToList();

            return new Book(asks, bids);
        }
開發者ID:dxzcc,項目名稱:ncrypto-currency-exchange,代碼行數:12,代碼來源:VoSParsers.cs

示例15: ParseWallets

        public static List<Wallet> ParseWallets(JObject fundsJson)
        {
            JObject availableFundsJson = fundsJson.Value<JObject>("available_funds");
            JObject lockedFundsJson = fundsJson.Value<JObject>("locked_funds");
            List<Wallet> wallets = new List<Wallet>();

            foreach (JProperty fund in availableFundsJson.Properties())
            {
                decimal availableFunds = availableFundsJson.Value<decimal>(fund.Name);
                JToken lockedFundJson;
                decimal lockedFunds;

                if (null != lockedFundsJson
                    && lockedFundsJson.TryGetValue(fund.Name, out lockedFundJson))
                {
                    lockedFunds = decimal.Parse(lockedFundJson.ToString());
                }
                else
                {
                    lockedFunds = 0.0m;
                }

                wallets.Add(new Wallet(fund.Name, availableFunds + lockedFunds, lockedFunds));
            }

            return wallets;
        }
開發者ID:dxzcc,項目名稱:ncrypto-currency-exchange,代碼行數:27,代碼來源:BterParsers.cs


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