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


C# JToken.ToObject方法代码示例

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


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

示例1: decipherAreasJSON

        /*
         * Gets all the sub-categories (or topics?) of jt, and hangs them under node?
         */
        //private static void decipherAreasJSON(JToken jt, Node node)
        private static void decipherAreasJSON(JToken jt, Category group)
        {
            if (jt is JProperty)
            {
                if (jt.ToObject<JProperty>().Name != IFIXIT_CATEGORY_OBJECT_KEY)
                {
            //                    Debug.WriteLine(" " + jt.ToObject<JProperty>().Name);

                    // since it's not a device, it must be a group
                    //Node curr = new Node(jt.ToObject<JProperty>().Name, new List<Node>());
                    Category curr = new Category(jt.ToObject<JProperty>().Name);

                    //FIXME this is where we add to the 1:M, right?
                    //group.Categories.Add(curr);
                    group.AddCategory(curr);
                    curr.Parent = group;
                    curr.parentName = group.Name;
                    if (jt.HasValues)
                    {
                        IJEnumerable<JToken> values = jt.Values();
                        foreach (JToken val in values)
                        {
                            decipherAreasJSON(val, curr);
                        }
                    }
                }
                // these are devices
                else
                {
                    IJEnumerable<JToken> devs = jt.Values();
                    foreach (JToken dev in devs)
                    {
                        Topic d = new Topic();
                        d.Name = dev.ToString();
                        /*
                        if (group.Devices == null)
                        {
                            group.Devices = new List<Topic>();
                        }
                         */
                        //group.Topics.Add(d);
                        group.AddTopic(d);
                        d.Parent = group;
                        d.parentName = group.Name;

                        //node.getChildrenList().Add(new Node(dev.ToString(), null));
            //                        Debug.WriteLine("  " + dev.ToString());
                    }
                }
            }
            else
            {
                // can currently safely ignore anything in this category
            //                Debug.WriteLine("\n" + jt.ToString() + " not a property\n");
            }
        }
开发者ID:mdabbagh88,项目名称:iFixit-WP,代码行数:60,代码来源:iFixitJSONHelper.cs

示例2: SafeAdd

 /// <summary>
 /// Write a property to a <see cref="JObject"/> only if it does not already exist and the value is not null.
 /// </summary>
 /// <param name="jobject">The <see cref="JObject"/> to write to.</param>
 /// <param name="propertyName">The name of the property to write.</param>
 /// <param name="token">The value of the property to write if it does not exist.</param>
 public static void SafeAdd(this JObject jobject, string propertyName, JToken token)
 {
     if (token != null && token.ToObject<object>() != null)
     {
         jobject[propertyName] = jobject[propertyName] ?? token;
     }
 }
开发者ID:CliftonMarien,项目名称:CKAN,代码行数:13,代码来源:JObjectExtensions.cs

示例3: Validate

 public ValidationResult Validate(string name, JToken value)
 {
     if (value.Type != JTokenType.Object)
     {
         ValidationResult.Fail(ValidationErrorCodes.Schema.UnexpectedType, $"Expected metadata object for property {name}.", name);
     }
     MetadataDefinition md;
     try
     {
         md = value.ToObject<MetadataDefinition>();
     }
     catch (JsonException ex)
     {
         return ValidationResult.Fail(ValidationErrorCodes.Schema.BadSchema, $"Bad metadata definition: {ex.Message}", name);
     }
     switch (md.Type)
     {
         case "string":
         case "integer":
         case "float":
         case "boolean":
             break;
         default:
             return ValidationResult.Fail(ValidationErrorCodes.Schema.UnexpectedType, $"Expected metadata object for property {name}.type.", name + ".type");
     }
     if (md.IsQueryable)
     {
         if (string.IsNullOrWhiteSpace(md.QueryName))
         {
             return ValidationResult.Fail(ValidationErrorCodes.Schema.BadSchema, $"Expected metadata object for property {name}.query_name.", name + ".query_name");
         }
     }
     return ValidationResult.Success;
 }
开发者ID:ansyral,项目名称:docfx,代码行数:34,代码来源:DefinitionObjectValidator.cs

示例4: GetDictionaryFromJsonData

 private Dictionary<DateTime, Ticket> GetDictionaryFromJsonData(JToken jtoken)
 {
     var result = jtoken.ToObject<Result<Ticket>>();
     
     return result.IsSuccessful && jtoken["data"] != null 
         ? JsonConvert.DeserializeObject<Dictionary<DateTime, Ticket>>(jtoken["data"].ToString())
         : default(Dictionary<DateTime, Ticket>);
 }
开发者ID:nikitadev,项目名称:TravelpayoutsAPI,代码行数:8,代码来源:SimpleSearchTicketsProvider.cs

示例5: ConvertJToken

 public override object ConvertJToken(JToken jToken)
 {
     // we need to decide what kind of profile this is
     if (jToken is JValue)
     {
         // it's just a string -
         return jToken.ToString();
     }
     // for now, this is the only other IProfile implementation
     return jToken.ToObject<ImageServiceProfile>();
 }
开发者ID:Riksarkivet,项目名称:iiif-model,代码行数:11,代码来源:ProfileSerialiser.cs

示例6: Set

        public override void Set(JToken jToken)
        {
            Person person = jToken.ToObject<Person>();

            this.FirstName = person.FirstName;
            this.LastName = person.LastName;
            this.Age = person.Age;
        }
开发者ID:mchound,项目名称:LewCMS,代码行数:8,代码来源:Person.cs

示例7: ConvertGepJsonTokenToObject

 public static Object ConvertGepJsonTokenToObject(JToken fieldToken, Field.FieldType fieldType)
 {
     switch (fieldType)
       {
     case ESRI.ArcGIS.Client.Field.FieldType.Integer:
     case ESRI.ArcGIS.Client.Field.FieldType.OID:
       return fieldToken.ToObject<Int32?>();
     case ESRI.ArcGIS.Client.Field.FieldType.SmallInteger:
       return fieldToken.ToObject<Int16?>();
     case ESRI.ArcGIS.Client.Field.FieldType.Double:
       return fieldToken.ToObject<Double?>();
     case ESRI.ArcGIS.Client.Field.FieldType.Single:
       return fieldToken.ToObject<Single?>();
     case ESRI.ArcGIS.Client.Field.FieldType.String:
     case ESRI.ArcGIS.Client.Field.FieldType.GlobalID:
     case ESRI.ArcGIS.Client.Field.FieldType.GUID:
     case ESRI.ArcGIS.Client.Field.FieldType.XML:
       return fieldToken.ToObject<String>();
     case ESRI.ArcGIS.Client.Field.FieldType.Date:
       return UnixTimeToDateTime((long?)fieldToken);
     case ESRI.ArcGIS.Client.Field.FieldType.Geometry:
     case ESRI.ArcGIS.Client.Field.FieldType.Blob:
     case ESRI.ArcGIS.Client.Field.FieldType.Raster:
     case ESRI.ArcGIS.Client.Field.FieldType.Unknown:
       return fieldToken.ToObject<Object>();
     default:
       return fieldToken.ToObject<Object>();
       }
 }
开发者ID:RockDr,项目名称:route-monitor-for-geoevent,代码行数:29,代码来源:Helper.cs

示例8: ChangeSet

 public ChangeSet(string sha, string workspace, string bucket, JToken author, IReadOnlyList<ChangeItem> changes)
 {
     Sha = sha;
     Workspace = workspace;
     Bucket = bucket;
     Author = author == null
         ? null
         : author.Type == JTokenType.String ? author.ToString() : author.ToObject<Author>().Email;
     Changes = changes;
 }
开发者ID:vtex,项目名称:workspaces-client-net,代码行数:10,代码来源:ChangeSet.cs

示例9: ConvertValue

		private object ConvertValue(JToken value)
		{
			switch (value.Type)
			{
				case JTokenType.Integer:
					return value.ToObject<int>();

				case JTokenType.Float:
					return value.ToObject<double>();

				case JTokenType.Boolean:
					return value.ToObject<bool>();

				case JTokenType.Date:
					return value.ToObject<DateTime>();

				case JTokenType.Guid:
					return value.ToObject<Guid>();

				case JTokenType.TimeSpan:
					return value.ToObject<TimeSpan>();

				default:
					return value.ToString();
			}
		}
开发者ID:chimpinano,项目名称:MvcRouteTester,代码行数:26,代码来源:JsonBodyReader.cs

示例10: SafeAdd

        /// <summary>
        /// Write a property to a <see cref="JObject"/> only if it does not already exist and the value is not null.
        /// </summary>
        /// <param name="jobject">The <see cref="JObject"/> to write to.</param>
        /// <param name="propertyName">The name of the property to write.</param>
        /// <param name="token">The value of the property to write if it does not exist.</param>
        public static void SafeAdd(this JObject jobject, string propertyName, JToken token)
        {
            if (String.IsNullOrWhiteSpace(propertyName))
            {
                Log.Warn("Asked to set a property named null on a JSON object!");
                return;
            }

            if (token != null && (token.HasValues || token.ToObject(typeof(object)) != null))
            {
                jobject[propertyName] = jobject[propertyName] ?? token;
            }
        }
开发者ID:Zor-X-L,项目名称:CKAN,代码行数:19,代码来源:JObjectExtensions.cs

示例11: SetAttribute

        internal void SetAttribute(string attributeName, JToken value)
        {
            object targetObject;
            PropertyInfo targetPropertyInfo;

            if (this.GetAttributeTarget(attributeName, out targetObject, out targetPropertyInfo))
            {
                targetPropertyInfo.SetValue(targetObject, value.ToObject(targetPropertyInfo.PropertyType));
            }
            else
            {
                throw new AutomationException("Could not access attribute {0}.", attributeName);
            }
        }
开发者ID:krishachetan89,项目名称:Winium.StoreApps,代码行数:14,代码来源:WiniumElement.GetSetAttribute.cs

示例12: GetValue

        private object GetValue(JToken token)
        {
            if (token is JObject)
                return new JObjectDataItem((JObject)token);

            if (token is JArray)
            {
                var jArray = (JArray)token;
                var result = new object[jArray.Count];
                for (var index = 0; index < jArray.Count; ++index)
                    result[index] = GetValue(jArray[index]);
                return result;
            }

            return token.ToObject<object>();
        }
开发者ID:kingkino,项目名称:azure-documentdb-datamigrationtool,代码行数:16,代码来源:JObjectDataItem.cs

示例13: OnReceived

        protected override void OnReceived(JToken message)
        {
            var invocation = message.ToObject<HubInvocation>();
            HubProxy hubProxy;

            if (_hubs.TryGetValue(invocation.Hub, out hubProxy))
            {
                if (invocation.State != null)
                {
                    foreach (var state in invocation.State)
                    {
                        hubProxy[state.Key] = state.Value;
                    }
                }
                hubProxy.InvokeEvent(invocation.Method, invocation.Args);
            }
            base.OnReceived(message);
        }
开发者ID:Avatarchik,项目名称:uSignalR,代码行数:18,代码来源:HubConnection.cs

示例14: OnReceived

		protected override void OnReceived(JToken message)
		{
			var _invocation = message.ToObject<HubInvocation>();
			HubProxy _hubProxy;

			if (m_hubs.TryGetValue(_invocation.Hub, out _hubProxy))
			{
				if (_invocation.State != null)
				{
					foreach (var state in _invocation.State)
					{
						_hubProxy[state.Key] = state.Value;
					}
				}
                Console.WriteLine("BER: " + _invocation.Method);
				_hubProxy.InvokeEvent(_invocation.Method, _invocation.Args);
			}
			base.OnReceived(message);
		}
开发者ID:BerndtHamboeck,项目名称:UnitySignalRVS2013,代码行数:19,代码来源:HubConnection.cs

示例15: GetListFromJsonData

        private IEnumerable<Ticket> GetListFromJsonData(string origin, JToken jtoken)
        {
            var result = jtoken.ToObject<Result<Ticket>>();
            if (result.IsSuccessful)
            {
                if (jtoken["data"] != null)
                {
                    var objs = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<int, Ticket>>>(jtoken["data"].ToString());
                    foreach (var element in objs)
                    {
                        foreach (var item in element.Value)
                        {
                            item.Value.Origin = origin;
                            item.Value.Destination = element.Key;

                            yield return item.Value;
                        }
                    }
                }
            }
        }
开发者ID:nikitadev,项目名称:TravelpayoutsAPI,代码行数:21,代码来源:SimpleSearchTicketsProvider.cs


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