• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# JToken类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: RedditUser

 public RedditUser(Reddit reddit, JToken json, IWebAgent webAgent)
     : base(json)
 {
     Reddit = reddit;
     WebAgent = webAgent;
     JsonConvert.PopulateObject(json["data"].ToString(), this, reddit.JsonSerializerSettings);
 }
开发者ID:JohnstonB,项目名称:RedditSharp-WP,代码行数:7,代码来源:RedditUser.cs


示例2: Diff

 public static JArray Diff(JArray source, JArray target, out bool changed, bool nullOnRemoved = false)
 {
     changed = source.Count != target.Count;
     var diffs = new JToken[target.Count];
     var commonLen = Math.Min(diffs.Length, source.Count);
     for (int i = 0; i < commonLen; i++)
     {
         if (target[i].Type == JTokenType.Object && source[i].Type == JTokenType.Object)
         {
             var subchanged = false;
             diffs[i] = Diff((JObject)source[i], (JObject)target[i], out subchanged, nullOnRemoved);
             if (subchanged) changed = true;
         }
         else if (target[i].Type == JTokenType.Array && source[i].Type == JTokenType.Array)
         {
             var subchanged = false;
             diffs[i] = Diff((JArray)source[i], (JArray)target[i], out subchanged, nullOnRemoved);
             if (subchanged) changed = true;
         }
         else
         {
             diffs[i] = target[i];
             if (!JToken.DeepEquals(source[i], target[i]))
                 changed = true;
         }
     }
     for (int i = commonLen; i < diffs.Length; i++)
     {
         diffs[i] = target[i];
         changed = true;
     }
     return new JArray(diffs);
 }
开发者ID:holajan,项目名称:dotvvm,代码行数:33,代码来源:JsonUtils.cs


示例3: Tax

 public Tax(JToken jTax)
     : this()
 {
     Kind = (string)jTax["kind"];
     ID = (string)jTax["iD"];
     Name = (string)jTax["name"];
 }
开发者ID:krystianwozniak92,项目名称:AirlineTicket,代码行数:7,代码来源:Tax.cs


示例4: JTokenReader

    /// <summary>
    /// Initializes a new instance of the <see cref="JTokenReader"/> class.
    /// </summary>
    /// <param name="token">The token to read from.</param>
    public JTokenReader(JToken token)
    {
      ValidationUtils.ArgumentNotNull(token, "token");

      _root = token;
      _current = token;
    }
开发者ID:RecursosOnline,项目名称:c-sharp,代码行数:11,代码来源:JTokenReader.cs


示例5: InitAsync

 public async Task<Comment> InitAsync(Reddit reddit, JToken json, IWebAgent webAgent, Thing sender)
 {
     var data = CommonInit(reddit, json, webAgent, sender);
     await ParseCommentsAsync(reddit, json, webAgent, sender);
     await Task.Factory.StartNew(() => JsonConvert.PopulateObject(data.ToString(), this, reddit.JsonSerializerSettings));
     return this;
 }
开发者ID:anavaino,项目名称:RedditSharp,代码行数:7,代码来源:Comment.cs


示例6: AddJOValue

 protected void AddJOValue(String key, JToken value)
 {
     if (this.data[key] == null)
         this.data.Add(key, value);
     else
         this.data[key].Replace(value);
 }
开发者ID:WinToosa,项目名称:mobilelogger,代码行数:7,代码来源:AbstractLogHandler.cs


示例7: IsMatch

 public override bool IsMatch(JToken t)
 {
     switch (Operator)
     {
         case QueryOperator.And:
             foreach (QueryExpression e in Expressions)
             {
                 if (!e.IsMatch(t))
                 {
                     return false;
                 }
             }
             return true;
         case QueryOperator.Or:
             foreach (QueryExpression e in Expressions)
             {
                 if (e.IsMatch(t))
                 {
                     return true;
                 }
             }
             return false;
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
开发者ID:veblush,项目名称:Newtonsoft.Json,代码行数:26,代码来源:QueryExpression.cs


示例8: ProcessMessage

        protected void ProcessMessage(JToken message) {
            var channel = (string)message["channel"];
            var chansplit = channel.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            if (chansplit.Length < 2) return;

            if (chansplit[0] == "meta") {
                switch (chansplit[1]) {
                    case "handshake":
                        HandshakeCallback((JObject)message);
                        break;
                    case "connect":
                        ConnectCallback((JObject)message);
                        break;
                    case "subscribe":
                        SubscribeCallback((JObject)message);
                        break;
                    case "unsubscribe":
                        UnsubscribeCallback((JObject)message);
                        break;
                }
                return;
            }

            if (message["successful"] != null) {
                PublishCallback((JObject)message);
            }

            if (PrimaryReciever != null) {
                PrimaryReciever.OnMessage((JObject)message);
            }
            OnReceive((JObject)message);
        }
开发者ID:cloudsdaleapp,项目名称:cloudsdale-metro,代码行数:33,代码来源:MessageHandler.cs


示例9: Parse

 internal static MovieLinks Parse(JToken json) {
     return new MovieLinks() {
         Alternate = (string)json["alternate"],
         Cast = (string)json["cast"],
         Reviews = (string)json["reviews"]
     };
 }
开发者ID:curtisrutland,项目名称:RottenTomatoes.NET,代码行数:7,代码来源:MovieLinks.cs


示例10: ApplyConfiguration

        /// <summary>
        /// Configure our FADN Provider
        /// </summary>
        /// <param name="configJson">Our params in Json</param>
        /// <returns>Configuration state</returns>
        public async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
        {
            // Retrieve config values set by Jackett's user
            ConfigData.LoadValuesFromJson(configJson);

            // Check & Validate Config
            ValidateConfig();

            // Setting our data for a better emulated browser (maximum security)
            // TODO: Encoded Content not supported by Jackett at this time
            // emulatedBrowserHeaders.Add("Accept-Encoding", "gzip, deflate");

            // If we want to simulate a browser
            if (ConfigData.Browser.Value)
            {

                // Clean headers
                _emulatedBrowserHeaders.Clear();

                // Inject headers
                _emulatedBrowserHeaders.Add("Accept", ConfigData.HeaderAccept.Value);
                _emulatedBrowserHeaders.Add("Accept-Language", ConfigData.HeaderAcceptLang.Value);
                _emulatedBrowserHeaders.Add("DNT", Convert.ToInt32(ConfigData.HeaderDnt.Value).ToString());
                _emulatedBrowserHeaders.Add("Upgrade-Insecure-Requests", Convert.ToInt32(ConfigData.HeaderUpgradeInsecure.Value).ToString());
                _emulatedBrowserHeaders.Add("User-Agent", ConfigData.HeaderUserAgent.Value);
                _emulatedBrowserHeaders.Add("Referer", LoginUrl);
            }

            await DoLogin();

            return IndexerConfigurationStatus.RequiresTesting;
        }
开发者ID:Jackett,项目名称:Jackett,代码行数:37,代码来源:Norbits.cs


示例11: ApplyConfiguration

        public async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
        {
            var loginPage = await RequestStringWithCookies(LoginUrl);
            CQ loginDom = loginPage.Content;
            var loginPostUrl = loginDom["#login"].Attr("action");

            configData.LoadValuesFromJson(configJson);
            var pairs = new Dictionary<string, string> {
                { "username", configData.Username.Value },
                { "password", configData.Password.Value }
            };
            // Get inital cookies
            CookieHeader = string.Empty;
            var response = await RequestLoginAndFollowRedirect(SiteLink + loginPostUrl, pairs, CookieHeader, true, null, LoginUrl);

            await ConfigureIfOK(response.Cookies, response.Content != null && response.Content.Contains("Velkommen tilbage"), () =>
            {
                CQ dom = response.Content;
                var messageEl = dom["inputs"];
                var errorMessage = messageEl.Text().Trim();
                throw new ExceptionWithConfigData(errorMessage, configData);
            });

            var profilePage = await RequestStringWithCookies(ProfileUrl, response.Cookies);
            CQ profileDom = profilePage.Content;
            var passKey = profileDom["input[name=resetkey]"].Parent().Text();
            passKey = passKey.Substring(0, passKey.IndexOf(' '));
            configData.RSSKey.Value = passKey;
            SaveConfig();
            return IndexerConfigurationStatus.RequiresTesting;
        }
开发者ID:m0thman,项目名称:Jackett,代码行数:31,代码来源:NxtGn.cs


示例12: FillObject

        public static PhoneCall FillObject(JToken data)
        {
            DateTime IndianTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"));

            PhoneCall Phonecall        = new PhoneCall();
            Phonecall.Action           = "1";
            Phonecall.AgentNumber      = data["agent_number"].ToString();
            Phonecall.BusinessCallType = data["business_call_type"].ToString();
            Phonecall.CallDuration     = (data["duration"] != null) ? data["duration"].ToString() : "0";
            Phonecall.CallId           = data["uuid"].ToString();
            Phonecall.CallType         = data["call_direction"].ToString();
            Phonecall.CallerId         = "";
            Phonecall.CustomerNumber   = data["customer_number"].ToString();
            Phonecall.Destination      = "";
            Phonecall.DispNumber       = data["knowlarity_number"].ToString();
            //Phonecall.EndTime          = "2015-09-01 11:35:52.090392+05:30";
            Phonecall.EndTime          = IndianTime.ToString("yyyy'-'MM'-'dd' 'HH':'mm':'ss.ffffff+5:30");
            Phonecall.Extension        = "5";
            Phonecall.HangupCause      = "900";
            Phonecall.ResourceUrl      = (data["call_recording"] != null) ? data["call_recording"].ToString() : String.Empty;
            Phonecall.StartTime        = "2015-08-11 11:35:47+05:30";
            Phonecall.Timezone         = "Asia/Kolkata";
            Phonecall.Type             = "";

            return Phonecall;
            
        }
开发者ID:JerryGoyal,项目名称:LeadSquared.SSEApplication,代码行数:27,代码来源:PhoneCall.cs


示例13: ConvertEditorConfig

        /// <summary>
        /// Converts the specified <code>token</code> into an instance of <code>IGridEditorConfig</code>.
        /// </summary>
        /// <param name="editor"></param>
        /// <param name="token">The instance of <code>JToken</code> representing the editor config.</param>
        /// <param name="config">The converted config.</param>
        public bool ConvertEditorConfig(GridEditor editor, JToken token, out IGridEditorConfig config) {
            
            config = null;

            switch (editor.Alias) {

                case "media_wide":
                case "media_wide_cropped":
                    config = GridEditorMediaConfig.Parse(editor, token as JObject);
                    break;

                case "banner_headline":
                case "banner_tagline":
                case "headline_centered":
                case "abstract":
                case "paragraph":
                case "quote_D":
                case "code":
                    config = GridEditorTextConfig.Parse(editor, token as JObject);
                    break;
                    
            }

            return config != null;
        
        }
开发者ID:skybrud,项目名称:Skybrud.Umbraco.GridData,代码行数:32,代码来源:FanoeGridConverter.cs


示例14: ConvertControlValue

        /// <summary>
        /// Converts the specified <code>token</code> into an instance of <code>IGridControlValue</code>.
        /// </summary>
        /// <param name="control">The parent control.</param>
        /// <param name="token">The instance of <code>JToken</code> representing the control value.</param>
        /// <param name="value">The converted value.</param>
        public bool ConvertControlValue(GridControl control, JToken token, out IGridControlValue value) {
            
            value = null;
            
            switch (control.Editor.Alias) {

                case "media_wide":
                case "media_wide_cropped":
                    value = GridControlMediaValue.Parse(control, token as JObject);
                    break;

                case "banner_headline":
                case "banner_tagline":
                case "headline_centered":
                case "abstract":
                case "paragraph":
                case "quote_D":
                case "code":
                    value = GridControlTextValue.Parse(control, token);
                    break;
            
            }
            
            return value != null;
        
        }
开发者ID:skybrud,项目名称:Skybrud.Umbraco.GridData,代码行数:32,代码来源:FanoeGridConverter.cs


示例15: ToObject

 private static object ToObject(JToken token)
 {
     if (token.Type == JTokenType.Object)
     {
         Dictionary<string, object> dict = new Dictionary<string, object>();
         foreach (JProperty prop in token)
         {
             dict.Add(prop.Name, ToObject(prop.Value));
         }
         return dict;
     }
     else if (token.Type == JTokenType.Array)
     {
         List<object> list = new List<object>();
         foreach (JToken value in token)
         {
             list.Add(ToObject(value));
         }
         return list;
     }
     else if (token.Type == JTokenType.Date)
     {
         // Hacky hack back
         // Can't figure out how to tell JSON.net not to deserialize datetimes
         return ((JValue)token).ToObject<DateTime>().ToString("yyyy-MM-dd'T'HH:mm:ssZ");
     }
     else
     {
         return ((JValue)token).Value;
     }
 }
开发者ID:modulexcite,项目名称:NToml,代码行数:31,代码来源:JsonHelper.cs


示例16: ApplyConfiguration

        public async Task ApplyConfiguration(JToken configJson)
        {
            var config = new ConfigurationDataBasicLogin();
            config.LoadValuesFromJson(configJson);
           
            var pairs = new Dictionary<string, string> {
				{ "username", config.Username.Value },
				{ "password", config.Password.Value }
			};

            var content = new FormUrlEncodedContent(pairs);

            var response = await client.PostAsync(LoginUrl, content);
            var responseContent = await response.Content.ReadAsStringAsync();

            if (!responseContent.Contains("logout.php"))
            {
                CQ dom = responseContent;
                var errorMessage = dom["td.text"].Text().Trim();
                throw new ExceptionWithConfigData(errorMessage, (ConfigurationData)config);
            }
            else
            {
                var configSaveData = new JObject();
                cookies.DumpToJson(SiteLink, configSaveData);
                SaveConfig(configSaveData);
                IsConfigured = true;
            }
        }
开发者ID:BoudewijnGlas,项目名称:Jackett,代码行数:29,代码来源:SceneTime.cs


示例17: ParseChannelAndChoose

		public static DiscordChannel ParseChannelAndChoose(JToken jmessage)
		{
			if (jmessage["type"].ToString().Equals("text", StringComparison.CurrentCultureIgnoreCase))
			{
				return new DiscordTextChannel
				{
					ID   = jmessage["id"].ToString(),
					Name = jmessage["name"].ToString(),
					Position = jmessage["position"].ToObject<int>(),
					GuildID  = jmessage["guild_id"].ToString(),
					Topic = jmessage["topic"].HasValues ? jmessage["topic"].ToString() : null,
					LastMessageID = jmessage["last_message_id"].ToString()
				};
			}
			else
			{
				return new DiscordVoiceChannel
				{
					ID   = jmessage["id"].ToString(),
					Name = jmessage["name"].ToString(),
					Position = jmessage["position"].ToObject<int>(),
					GuildID = jmessage["guild_id"].ToString(),
					Bitrate = jmessage["bitrate"].ToObject<int>()
				};
			}
		}
开发者ID:romgerman,项目名称:DiscordUWP8,代码行数:26,代码来源:JsonHelper.cs


示例18: ApplyConfiguration

        public async Task ApplyConfiguration(JToken configJson)
        {
            var incomingConfig = new ConfigurationDataBasicLogin();
            incomingConfig.LoadValuesFromJson(configJson);
            var pairs = new Dictionary<string, string> {
                { "username", incomingConfig.Username.Value },
                { "password", incomingConfig.Password.Value }
            };
            var request = new Utils.Clients.WebRequest()
            {
                Url = LoginUrl,
                Type = RequestType.POST,
                Referer = SiteLink,
                PostData = pairs
            };
            var response = await webclient.GetString(request);
            CQ splashDom = response.Content;
            var link = splashDom[".trow2 a"].First();
            var resultPage = await RequestStringWithCookies(link.Attr("href"), response.Cookies);
            CQ resultDom = resultPage.Content;

            await ConfigureIfOK(response.Cookies, resultPage.Content.Contains("/logout.php"), () =>
            {
                var tries = resultDom["#main tr:eq(1) td font"].First().Text();
                var errorMessage = "Incorrect username or password! " + tries + " tries remaining.";
                throw new ExceptionWithConfigData(errorMessage, (ConfigurationData)incomingConfig);
            });
        }
开发者ID:lin0sspice,项目名称:Jackett,代码行数:28,代码来源:ImmortalSeed.cs


示例19: GetReturnCodeForSuccess

        private static int GetReturnCodeForSuccess(JToken response)
        {
            if (response["200"] != null)
            {
                return 200;
            }

            if (response["202"] != null)
            {
                return 202;
            }

            if (response["201"] != null)
            {
                return 201;
            }

            if (response["206"] != null)
            {
                return 206;
            }

            if (response["204"] != null)
            {
                return 204;
            }

            throw new InvalidOperationException("Succes code not found");
        }
开发者ID:sudarsanan-krishnan,项目名称:DynamicsCRMConnector,代码行数:29,代码来源:Swagger20Parser.cs


示例20: TryGetInt

 private static bool TryGetInt(JToken json, out int value)
 {
     var x = json as JValue;
     var isInt = x != null && x.Type == JTokenType.Integer;
     value = isInt ? x.ToObject<int>() : 0;
     return isInt;
 }
开发者ID:ufcpp,项目名称:UfcppSample,代码行数:7,代码来源:PointJson.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# JTokenType类代码示例发布时间:2022-05-24
下一篇:
C# JSchemaReader类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap