本文整理汇总了C#中JObject.Value方法的典型用法代码示例。如果您正苦于以下问题:C# JObject.Value方法的具体用法?C# JObject.Value怎么用?C# JObject.Value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JObject
的用法示例。
在下文中一共展示了JObject.Value方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateContainer
DocumentContainer CreateContainer(JObject jObject)
{
DocumentContainer container = new DocumentContainer();
container.Id = jObject.Value<string>("_id");
if (container.Id == null)
return null;
container.Key = jObject.Value<string>("_key");
if (container.Key == null)
return null;
container.Rev = jObject.Value<string>("_rev");
if (container.Rev == null)
return null;
container.From = jObject.Value<string>("_from");
container.To = jObject.Value<string>("_to");
container.Document = jObject;
return container;
}
示例2: processResponseOk
void processResponseOk(GcmAsyncParameters asyncParam)
{
var result = new GcmMessageTransportResponse()
{
ResponseCode = GcmMessageTransportResponseCode.Ok,
Message = asyncParam.Message
};
var json = new JObject();
var str = string.Empty;
try { str = (new StreamReader(asyncParam.WebResponse.GetResponseStream())).ReadToEnd(); }
catch { }
try { json = JObject.Parse(str); }
catch { }
result.NumberOfCanonicalIds = json.Value<long>("canonical_ids");
result.NumberOfFailures = json.Value<long>("failure");
result.NumberOfSuccesses = json.Value<long>("success");
var jsonResults = json["results"] as JArray;
if (jsonResults == null)
jsonResults = new JArray();
foreach (var r in jsonResults)
{
var msgResult = new GcmMessageResult();
msgResult.MessageId = r.Value<string>("message_id");
msgResult.CanonicalRegistrationId = r.Value<string>("registration_id");
msgResult.ResponseStatus = GcmMessageTransportResponseStatus.Ok;
if (!string.IsNullOrEmpty(msgResult.CanonicalRegistrationId))
{
msgResult.ResponseStatus = GcmMessageTransportResponseStatus.CanonicalRegistrationId;
}
else if (r["error"] != null)
{
var err = r.Value<string>("error") ?? "";
switch (err.ToLowerInvariant().Trim())
{
case "ok":
msgResult.ResponseStatus = GcmMessageTransportResponseStatus.Ok;
break;
case "missingregistration":
msgResult.ResponseStatus = GcmMessageTransportResponseStatus.MissingRegistrationId;
break;
case "unavailable":
msgResult.ResponseStatus = GcmMessageTransportResponseStatus.Unavailable;
break;
case "notregistered":
msgResult.ResponseStatus = GcmMessageTransportResponseStatus.NotRegistered;
break;
case "invalidregistration":
msgResult.ResponseStatus = GcmMessageTransportResponseStatus.InvalidRegistration;
break;
case "mismatchsenderid":
msgResult.ResponseStatus = GcmMessageTransportResponseStatus.MismatchSenderId;
break;
case "messagetoobig":
msgResult.ResponseStatus = GcmMessageTransportResponseStatus.MessageTooBig;
break;
case "invaliddatakey":
msgResult.ResponseStatus = GcmMessageTransportResponseStatus.InvalidDataKey;
break;
case "invalidttl":
msgResult.ResponseStatus = GcmMessageTransportResponseStatus.InvalidTtl;
break;
case "internalservererror":
msgResult.ResponseStatus = GcmMessageTransportResponseStatus.InternalServerError;
break;
default:
msgResult.ResponseStatus = GcmMessageTransportResponseStatus.Error;
break;
}
}
result.Results.Add(msgResult);
}
asyncParam.WebResponse.Close();
int index = 0;
var response = result;
foreach (var r in response.Results)
{
var singleResultNotification = GcmNotification.ForSingleResult(response, index);
if (r.ResponseStatus == GcmMessageTransportResponseStatus.Ok)
{
asyncParam.Callback(this, new SendNotificationResult(singleResultNotification));
}
else if (r.ResponseStatus == GcmMessageTransportResponseStatus.CanonicalRegistrationId)
{
var newRegistrationId = r.CanonicalRegistrationId;
var oldRegistrationId = string.Empty;
if (singleResultNotification.RegistrationIds != null && singleResultNotification.RegistrationIds.Count > 0)
oldRegistrationId = singleResultNotification.RegistrationIds[0];
asyncParam.Callback(this, new SendNotificationResult(singleResultNotification, false, new DeviceSubscriptonExpiredException()) { OldSubscriptionId = oldRegistrationId, NewSubscriptionId = newRegistrationId, IsSubscriptionExpired = true });
}
else if (r.ResponseStatus == GcmMessageTransportResponseStatus.Unavailable)
{
asyncParam.Callback(this, new SendNotificationResult(singleResultNotification, true, new Exception("Unavailable Response Status")));
}
else if (r.ResponseStatus == GcmMessageTransportResponseStatus.NotRegistered)
//.........这里部分代码省略.........