本文整理汇总了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]);
}
示例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>();
}
示例3: DropboxInfo
public DropboxInfo(JObject payload)
{
Deployer = DropboxHelper.Dropbox;
NewRef = "dummy";
OldRef = "dummy";
DeployInfo = payload.ToObject<DropboxDeployInfo>();
}
示例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;
}
示例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;
}
}
示例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>();
}
示例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();
}
}
示例8: DropboxInfo
public DropboxInfo(JObject payload, RepositoryType repositoryType)
{
Deployer = DropboxHelper.Dropbox;
DeployInfo = payload.ToObject<DropboxDeployInfo>();
RepositoryType = repositoryType;
IsReusable = false;
}
示例9: ParseCredentials
public override ProviderCredentials ParseCredentials(JObject serialized)
{
if (serialized == null)
{
throw new ArgumentNullException("serialized");
}
return serialized.ToObject<CustomLoginProviderCredentials>();
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}