本文整理汇总了C#中JToken.Get方法的典型用法代码示例。如果您正苦于以下问题:C# JToken.Get方法的具体用法?C# JToken.Get怎么用?C# JToken.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JToken
的用法示例。
在下文中一共展示了JToken.Get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ThrowInvalidResponse
/// <summary>
/// Throw an exception for an invalid response to a web request.
/// </summary>
/// <param name="request">The request.</param>
/// <param name="response">The response.</param>
/// <param name="body">The body of the response as JSON.</param>
private static void ThrowInvalidResponse(IServiceFilterRequest request, IServiceFilterResponse response, JToken body)
{
Debug.Assert(request != null, "request cannot be null!");
Debug.Assert(response != null, "response cannot be null!");
Debug.Assert(
response.ResponseStatus != ServiceFilterResponseStatus.Success ||
response.StatusCode >= 400,
"response should be failing!");
// Create either an invalid response or connection failed message
// (check the status code first because some status codes will
// set a protocol ErrorStatus).
string message = null;
if (response.StatusCode >= 400)
{
if (body != null)
{
if (body.Type == JTokenType.String)
{
// User scripts might return errors with just a plain string message as the
// body content, so use it as the exception message
message = body.ToString();
}
else if (body.Type == JTokenType.Object)
{
// Get the error message, but default to the status description
// below if there's no error message present.
message = body.Get("error").AsString() ??
body.Get("description").AsString();
}
}
if (string.IsNullOrWhiteSpace(message))
{
message = string.Format(
CultureInfo.InvariantCulture,
Resources.MobileServiceClient_ErrorMessage,
response.StatusDescription);
}
}
else
{
message = string.Format(
CultureInfo.InvariantCulture,
Resources.MobileServiceClient_ErrorMessage,
response.ResponseStatus);
}
// Combine the pieces and throw the exception
throw CreateMobileServiceException(message, request, response);
}
示例2:
void ICustomMobileServiceTableSerialization.Deserialize(JToken value)
{
int? id = value.Get("id").AsInteger();
if (id != null)
{
Id = id.Value;
}
Name = value.Get("name").AsString();
JArray children = value["children"] as JArray;
if (children != null)
{
Children.AddRange(children.Select(MobileServiceTableSerializer.Deserialize<SimpleTree>));
}
}