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


C# JObject.ToObject方法代码示例

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


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

示例1: Create

 public Plugin Create(JObject bag)
 {
     var name = bag["name"].ToString();
     if (!_factories.ContainsKey(name))
     {
         return bag.ToObject<Plugin>();
     }
     return (Plugin)bag.ToObject(_factories[name]);
 }
开发者ID:trackmatic,项目名称:kong.net,代码行数:9,代码来源:DefaultPluginFactory.cs

示例2: FromJObject

        /// <summary>
        /// Deserializes a JSON object to a <see cref="LaunchConfiguration"/> instance of the proper type.
        /// </summary>
        /// <param name="jsonObject">The JSON object representing the launch configuration.</param>
        /// <returns>A <see cref="LaunchConfiguration"/> object corresponding to the JSON object.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="jsonObject"/> is <see langword="null"/>.</exception>
        public static LaunchConfiguration FromJObject(JObject jsonObject)
        {
            if (jsonObject == null)
                throw new ArgumentNullException("jsonObject");

            JToken launchType = jsonObject["type"];
            if (launchType == null || launchType.ToObject<LaunchType>() == LaunchType.LaunchServer)
                return jsonObject.ToObject<ServerLaunchConfiguration>();

            return jsonObject.ToObject<GenericLaunchConfiguration>();
        }
开发者ID:asmajlovic,项目名称:openstack.net,代码行数:17,代码来源:LaunchConfiguration.cs

示例3: DropboxInfo

 public DropboxInfo(JObject payload)
 {
     Deployer = DropboxHelper.Dropbox;
     NewRef = "dummy";
     OldRef = "dummy";
     DeployInfo = payload.ToObject<DropboxDeployInfo>();
 }
开发者ID:dpvreony-forks,项目名称:kudu,代码行数:7,代码来源:DropboxHandler.cs

示例4: DropboxInfo

 public DropboxInfo(JObject payload)
 {
     Deployer = DropboxHelper.Dropbox;
     DeployInfo = payload.ToObject<DropboxDeployInfo>();
     // This ensure that the fetch handler provides an underlying Git repository.
     RepositoryType = RepositoryType.Git;
 }
开发者ID:BrianVallelunga,项目名称:kudu,代码行数:7,代码来源:DropboxHandler.cs

示例5: PostBookmark

        public dynamic PostBookmark(JObject Json)
        {
            JsonModels.BookMarkObj AddBookM = Json.ToObject<JsonModels.BookMarkObj>();

            Bookmark bk = new Bookmark()
            {
                Url = AddBookM.Url,
                Title = AddBookM.Title,
                Tags = AddBookM.Tags,
                Date = DateTime.Now,
                Active = true
                //Users = new List<User>(){
                //     new User(){
                //         Name=AddBookM.tags
                //     }
                // }
            };

            //Log Lg = new Log()
            //{
            //    Date = DateTime.Now
            //};
            try
            {
                MvcWithNGContext NgContext = new MvcWithNGContext();
                NgContext.Bookmarks.Add(bk);
                NgContext.SaveChanges();
                return "Link Bookmarked :) ";
            }
            catch (Exception e)
            {
                return e;
            }
        }
开发者ID:ng-parth,项目名称:MvcWithNG,代码行数:34,代码来源:BookMeController.cs

示例6: FromJObject

        /// <summary>
        /// Deserializes a JSON object to a <see cref="NotificationDetails"/> instance of the proper type.
        /// </summary>
        /// <param name="notificationTypeId">The notification type ID.</param>
        /// <param name="obj">The JSON object representing the notification details.</param>
        /// <returns>A <see cref="NotificationDetails"/> object corresponding to the JSON object.</returns>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="notificationTypeId"/> is <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="obj"/> is <see langword="null"/>.</para>
        /// </exception>
        public static NotificationDetails FromJObject(NotificationTypeId notificationTypeId, JObject obj)
        {
            if (notificationTypeId == null)
                throw new ArgumentNullException("notificationTypeId");
            if (obj == null)
                throw new ArgumentNullException("obj");

            if (notificationTypeId == NotificationTypeId.Webhook)
                return obj.ToObject<WebhookNotificationDetails>();
            else if (notificationTypeId == NotificationTypeId.Email)
                return obj.ToObject<EmailNotificationDetails>();
            else if (notificationTypeId == NotificationTypeId.PagerDuty)
                return obj.ToObject<PagerDutyNotificationDetails>();
            else
                return obj.ToObject<GenericNotificationDetails>();
        }
开发者ID:asmajlovic,项目名称:openstack.net,代码行数:27,代码来源:NotificationDetails.cs

示例7: PostRate

        public async Task PostRate(double rated)
        {
            int user = MediateClass.UserVM.UserInfo.UserId;
            int store = MediateClass.KiotVM.SelectedStore.StoreId;

            Rating UserRate = new Rating(user, store, rated);

            JObject result = new JObject();
            JToken body = JToken.FromObject(UserRate);
            try
            {
                if (Utilities.Helpers.NetworkHelper.Instance.HasInternetConnection)
                {
                    var message = await App.MobileService.InvokeApiAsync("StatisticRatings", body, HttpMethod.Post, null);
                    result = JObject.Parse(message.ToString());

                    Kios temp = result.ToObject<Kios>();

                    UpdateDataLocal(temp, UserRate);
                }
            }
            catch (Exception ex)
            {
                await new MessageDialog(ex.Message.ToString(), "Notification!").ShowAsync();
            }            
        }
开发者ID:monpham2310,项目名称:PayBay,代码行数:26,代码来源:RatingViewModel.cs

示例8: DropboxInfo

 public DropboxInfo(JObject payload, RepositoryType repositoryType)
 {
     Deployer = DropboxHelper.Dropbox;
     DeployInfo = payload.ToObject<DropboxDeployInfo>();
     RepositoryType = repositoryType;
     IsReusable = false;
 }
开发者ID:WeAreMammoth,项目名称:kudu-obsolete,代码行数:7,代码来源:DropboxHandler.cs

示例9: ParseCredentials

 public override ProviderCredentials ParseCredentials(JObject serialized)
 {
     if (serialized == null)
     {
         throw new ArgumentNullException("serialized");
     }
     return serialized.ToObject<CustomLoginProviderCredentials>();
 }
开发者ID:joelgasso,项目名称:blogcodes,代码行数:8,代码来源:CustomLoginProvider.cs

示例10: OnGameCreated

 public void OnGameCreated(JObject jsonObject)
 {
     Debug.Log("Game created: " + jsonObject);
     GameCreatedMessage message = jsonObject.ToObject<GameCreatedMessage>();
     long id = message.gameId;
     JoinRequest request = new JoinRequest(OnGameJoined, id);
     GameClient.Instance.SendRequest(request);
 }
开发者ID:wx3,项目名称:galacdecks,代码行数:8,代码来源:GameInstanceBootstrap.cs

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

示例12: DeserializeToClr

        static object DeserializeToClr(int targetVersion, JObject targetJObject)
        {
            // ----- actual deserialization to clr type
            // todo consider type
            var targetClrType = ClrTypeFor(targetVersion);

            // what do we need to desarialize the json to a typed object
            return targetJObject.ToObject(targetClrType);
        }
开发者ID:michelschep,项目名称:VersioningExplorer,代码行数:9,代码来源:JsonSerializer.cs

示例13: AddUser

 public bool AddUser(JObject data)
 {
     var user = data.ToObject<User>();
     if (UserRegistry.Add(user))
     {
         UserStorage.Add(user.Id, data);
         return true;
     }
     return false;
 }
开发者ID:pitlabcloud,项目名称:activity-cloud,代码行数:10,代码来源:UserController.cs

示例14: LogEvent

        public HttpResponseMessage LogEvent(string telemetryEvent, JObject properties)
        {
            var context = new HttpContextWrapper(HttpContext.Current);
            if (context.IsBrowserRequest())
            {
                var userName = User != null && User.Identity != null && !string.IsNullOrEmpty(User.Identity.Name)
                    ? User.Identity.Name
                    : "-";
                var anonymousUserName = SecurityManager.GetAnonymousUserName(context);

                if (telemetryEvent.Equals("INIT_USER", StringComparison.OrdinalIgnoreCase))
                {
                    var dic = properties != null
                        ? properties.ToObject<Dictionary<string, string>>()
                        : new Dictionary<string, string>();

                    Func<string, string> cleanUp = (s) => string.IsNullOrEmpty(s) ? "-" : s;
                    var referer = cleanUp(dic.Where(p => p.Key == "origin").Select(p => p.Value).FirstOrDefault());
                    var cid = cleanUp(dic.Where(p => p.Key == "cid").Select(p => p.Value).FirstOrDefault());
                    var sv = cleanUp(dic.Where(p => p.Key == "sv").Select(p => p.Value).FirstOrDefault());

                    SimpleTrace.TraceInformation("{0}; {1}; {2}; {3}; {4}; {5}",
                            AnalyticsEvents.AnonymousUserInit,
                            userName,
                            ExperimentManager.GetCurrentExperiment(),
                            referer,
                            cid,
                            sv
                        );
                }
                else
                {
                    SimpleTrace.Analytics.Information(AnalyticsEvents.UiEvent, telemetryEvent, properties);

                    var eventProperties = properties != null
                        ? properties.ToObject<Dictionary<string, string>>().Select(e => e.Value).Aggregate((a, b) => string.Join(" ", a, b))
                        : string.Empty;
                    SimpleTrace.TraceInformation("{0}; {1}; {2}; {3}; {4}", AnalyticsEvents.OldUiEvent, telemetryEvent, userName, eventProperties, anonymousUserName);
                }
            }
            return Request.CreateResponse(HttpStatusCode.Accepted);
        }
开发者ID:davidlai-msft,项目名称:SimpleWAWS,代码行数:42,代码来源:TelemetryController.cs

示例15: AddActivity

        public bool AddActivity(NotificationType type, JObject data, bool asHistory = false)
        {
            var activity = data.ToObject<Activity>();
            if (asHistory) activity.IsHistory = true;
            if (_activityRegistry.Add(activity))
            {
                _activityStorage.Add(data.ToObject<Activity>().Id, data);
                PutParticipantsOnSubscription(activity);

                if (!asHistory) Notifier.Subscribe(ConnectionId, activity.Id);
                // Notify owner and participants
                Notifier.NotifyGroup(activity.Owner.Id, type, data);
                foreach (var participant in activity.Participants)
                    Notifier.NotifyGroup(participant.Id, type, data);

                if (!asHistory) _fileController.Sync(SyncType.Added, activity, ConnectionId);
                return true;
            }
            return false;
        }
开发者ID:pitlabcloud,项目名称:activity-cloud,代码行数:20,代码来源:ActivityController.cs


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