本文整理汇总了C#中JsonObject.HasValue方法的典型用法代码示例。如果您正苦于以下问题:C# JsonObject.HasValue方法的具体用法?C# JsonObject.HasValue怎么用?C# JsonObject.HasValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonObject
的用法示例。
在下文中一共展示了JsonObject.HasValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
/// <summary>
/// Gets an instance of <code>YouTubeVideoStatus</code> from the specified <code>JsonObject</code>.
/// </summary>
/// <param name="obj">The instance of <code>JsonObject</code> to parse.</param>
public static YouTubeVideoStatus Parse(JsonObject obj) {
if (obj == null) return null;
// Parse the upload status
YouTubeVideoUploadStatus uploadStatus;
string strUploadStatus = obj.GetString("uploadStatus");
if (!Enum.TryParse(strUploadStatus, true, out uploadStatus)) {
throw new Exception("Unknown upload status \"" + strUploadStatus + "\" - please create an issue so it can be fixed https://github.com/abjerner/Skybrud.Social/issues/new");
}
YouTubeVideoFailureReason? failureReason = null;
if (obj.HasValue("failureReason")) {
YouTubeVideoFailureReason reason;
string strReason = obj.GetString("failureReason");
if (Enum.TryParse(strReason, out reason)) {
failureReason = reason;
} else {
throw new Exception("Unknown failure reason \"" + strReason + "\" - please create an issue so it can be fixed https://github.com/abjerner/Skybrud.Social/issues/new");
}
}
YouTubeVideoRejectionReason? rejectionReason = null;
if (obj.HasValue("rejectionReason")) {
YouTubeVideoRejectionReason reason;
string strReason = obj.GetString("rejectionReason");
if (Enum.TryParse(strReason, out reason)) {
rejectionReason = reason;
} else {
throw new Exception("Unknown rejection reason \"" + strReason + "\" - please create an issue so it can be fixed https://github.com/abjerner/Skybrud.Social/issues/new");
}
}
// Parse the privacy status
YouTubePrivacyStatus privacyStatus;
string strPrivacyStatus = obj.GetString("privacyStatus");
if (!Enum.TryParse(strPrivacyStatus, true, out privacyStatus)) {
throw new Exception("Unknown privacy status \"" + strPrivacyStatus + "\" - please create an issue so it can be fixed https://github.com/abjerner/Skybrud.Social/issues/new");
}
// Parse the privacy status
YouTubeVideoLicense videoLicense;
string strLicense = obj.GetString("license");
if (!Enum.TryParse(strLicense, true, out videoLicense)) {
throw new Exception("Unknown license \"" + strLicense + "\" - please create an issue so it can be fixed https://github.com/abjerner/Skybrud.Social/issues/new");
}
return new YouTubeVideoStatus(obj) {
UploadStatus = uploadStatus,
PrivacyStatus = privacyStatus,
FailureReason = failureReason,
RejectionReason = rejectionReason,
License = videoLicense,
IsEmbeddable = obj.GetBoolean("embeddable"),
PublicStatsViewable = obj.GetBoolean("publicStatsViewable")
};
}
示例2: ValidateResponse
public static void ValidateResponse(JsonObject obj) {
// Check whether "obj" is null
if (obj == null) throw new ArgumentNullException("obj");
// Get the "meta" object
JsonObject meta = obj.GetObject("meta");
// In special cases the root object is meta ()
if (meta == null && obj.HasValue("code")) {
meta = obj;
}
// In some special cases like during the OAuth authentication, the
// root object is actually the "meta" object if any errors occur
if (meta == null) {
// Get some values from the "obj" object
int code = obj.GetInt("code");
string type = obj.GetString("error_type");
string message = obj.GetString("error_message");
if (obj.HasValue("code")) {
if (type == "OAuthException") throw new InstagramOAuthException(code, type, message);
throw new InstagramException(code, type, message);
}
// Should be OK by now
return;
}
// Most responses will have a meta object along with a response code
if (meta.HasValue("code")) {
// Get some values from the "meta" object
int code = meta.GetInt("code");
string type = meta.GetString("error_type");
string message = meta.GetString("error_message");
// If "code" is 200, everything went fine :D
if (code == 200) return;
// Now throw some exceptions
if (type == "OAuthException") throw new InstagramOAuthException(code, type, message);
if (type == "OAuthAccessTokenException") throw new InstagramOAuthAccessTokenException(code, type, message);
if (type == "APINotFoundError") throw new InstagramNotFoundException(code, type, message);
throw new InstagramException(code, type, message);
}
throw new Exception("Invalid response received from server");
}
示例3: Parse
public static FacebookEvent Parse(JsonObject obj) {
return new FacebookEvent {
Id = obj.GetLong("id"),
Name = obj.GetString("name"),
Description = obj.GetString("description"),
StartTime = obj.GetDateTime("start_time"),
EndTime = obj.HasValue("end_time") ? (DateTime?) obj.GetDateTime("end_time") : null,
TimeZone = obj.GetString("timezone"),
IsDateOnly = obj.HasValue("is_date_only") && obj.GetBoolean("is_date_only"),
Location = obj.GetString("location"),
Privacy = obj.GetString("privacy"),
UpdatedTime = obj.GetDateTime("updated_time")
};
}
示例4: Parse
/// <summary>
/// Gets an instance of <var>AnalyticsDataResponse</var> from the specified
/// <var>JsonObject</var>.
/// </summary>
/// <param name="obj">The instance of <var>JsonObject</var> to parse.</param>
public static AnalyticsDataResponse Parse(JsonObject obj) {
// Check whether "obj" is NULL
if (obj == null) return null;
// Check for any API errors
if (obj.HasValue("error")) {
JsonObject error = obj.GetObject("error");
throw new GoogleApiException(error.GetInt("code"), error.GetString("message"));
}
// Initialize the response object
AnalyticsDataResponse response = new AnalyticsDataResponse {
Query = obj.GetObject("query", AnalyticsDataQuery.Parse),
ColumnHeaders = obj.GetArray("columnHeaders", AnalyticsDataColumnHeader.Parse)
};
// Parse the rows
JsonArray rows = obj.GetArray("rows");
if (rows == null) {
response.Rows = new AnalyticsDataRow[0];
} else {
response.Rows = new AnalyticsDataRow[rows.Length];
for (int i = 0; i < rows.Length; i++) {
response.Rows[i] = new AnalyticsDataRow {
Index = i,
Cells = rows.GetArray(i).Cast<string>()
};
}
}
return response;
}
示例5: Parse
/// <summary>
/// Gets an instance of <code>FacebookDebugTokenData</code> from the specified <var>JsonObject</var>.
/// </summary>
/// <param name="obj">The instance of <code>JsonObject</code> to parse.</param>
public static FacebookDebugTokenData Parse(JsonObject obj) {
// Check if NULL
if (obj == null) return null;
// If an access token doesn't have an expire date, it may be specified as "0". In other scenarios, the
// property is not present at all. In either case, we should set the "ExpiresAt" property to "NULL".
DateTime? expiresAt = null;
if (obj.HasValue("expires_at")) {
int value = obj.GetInt32("expires_at");
if (value > 0) expiresAt = SocialUtils.GetDateTimeFromUnixTime(value);
}
// Parse the array of scopes
FacebookScope[] scopes = (
from name in obj.GetArray<string>("scopes") ?? new string[0]
select FacebookScope.GetScope(name) ?? new FacebookScope(name)
).ToArray();
// Initialize the instance of FacebookDebugTokenData
return new FacebookDebugTokenData(obj) {
AppId = obj.GetInt64("app_id"),
Application = obj.GetString("application"),
ExpiresAt = expiresAt,
IsValid = obj.GetBoolean("is_valid"),
IssuedAt = obj.HasValue("issued_at") ? (DateTime?) obj.GetDateTimeFromUnixTimestamp("issued_at") : null,
UserId = obj.GetString("user_id"),
Scopes = scopes
};
}
示例6: Parse
/// <summary>
/// Gets an instance of <var>FacebookFeedResponse</var> from the specified <var>JsonObject</var>.
/// </summary>
/// <param name="obj">The instance of <var>JsonObject</var> to parse.</param>
public static FacebookFeedResponse Parse(JsonObject obj) {
if (obj == null) return null;
if (obj.HasValue("error")) throw obj.GetObject("error", FacebookException.Parse);
return new FacebookFeedResponse {
Data = obj.GetArray("data", FacebookFeedEntry.Parse),
Paging = obj.GetObject("paging", FacebookPaging.Parse)
};
}
示例7: Parse
public static FacebookMeResponse Parse(JsonObject obj) {
if (obj == null) return null;
if (obj.HasValue("error")) throw obj.GetObject("error", FacebookException.Parse);
return new FacebookMeResponse {
Id = obj.GetLong("id"),
Name = obj.GetString("name"),
FirstName = obj.GetString("first_name"),
LastName = obj.GetString("last_name"),
Link = obj.GetString("link"),
UserName = obj.GetString("username"),
Gender = obj.GetString("gender"),
TimeZone = obj.HasValue("timezone") ? (int?) obj.GetInt("timezone") : null,
Locale = obj.GetString("locale"),
IsVerified = obj.HasValue("verified") ? (bool?) obj.GetBoolean("verified") : null,
UpdatedTime = obj.GetDateTime("updated_time")
};
}
示例8: Parse
public static FacebookPhotosResponse Parse(JsonObject obj) {
if (obj == null) return null;
if (obj.HasValue("error")) throw obj.GetObject("error", FacebookException.Parse);
return new FacebookPhotosResponse {
Data = FacebookPhoto.ParseMultiple(obj.GetArray("data")),
Paging = FacebookPaging.Parse(obj.GetObject("paging"))
};
}
示例9: Parse
public static FacebookEventSummary Parse(JsonObject obj) {
return new FacebookEventSummary {
Id = obj.GetLong("id"),
Name = obj.GetString("name"),
StartTime = obj.GetDateTime("start_time"),
EndTime = obj.HasValue("end_time") ? (DateTime?) obj.GetDateTime("end_time") : null,
TimeZone = obj.GetString("timezone"),
Location = obj.GetString("location")
};
}
示例10: Parse
public static FacebookException Parse(JsonObject obj) {
return new FacebookException(
obj.GetInt("code"),
obj.GetString("type"),
obj.GetString("message"),
obj.HasValue("error_subcode") ? obj.GetInt("error_subcode") : 0
);
}
示例11: Parse
/// <summary>
/// Gets an instance of <code>FacebookApp</code> from the specified <code>JsonObject</code>.
/// </summary>
/// <param name="obj">The instance of <code>JsonObject</code> to parse.</param>
public static FacebookApp Parse(JsonObject obj) {
if (obj == null) return null;
return new FacebookApp(obj) {
Id = obj.GetInt64("id"),
Name = obj.GetString("name"),
Description = obj.GetString("description"),
Category = obj.GetString("category"),
SubCategory = obj.GetString("subcategory"),
Link = obj.GetString("link"),
Namespace = obj.GetString("namespace"),
IconUrl = obj.GetString("icon_url"),
LogoUrl = obj.GetString("logo_url"),
DailyActiveUsers = obj.HasValue("weekly_active_users") ? (int?)obj.GetInt32("weekly_active_users") : null,
WeeklyActiveUsers = obj.HasValue("weekly_active_users") ? (int?)obj.GetInt32("weekly_active_users") : null,
MonthlyActiveUsers = obj.HasValue("monthly_active_users") ? (int?)obj.GetInt32("monthly_active_users") : null,
DailyActiveUserRank = obj.HasValue("daily_active_users_rank") ? (int?)obj.GetInt32("daily_active_users_rank") : null,
MontlyActiveUserRank = obj.HasValue("monthly_active_users_rank") ? (int?)obj.GetInt32("monthly_active_users_rank") : null,
};
}
示例12: Parse
public static FacebookCommentSummary Parse(JsonObject obj) {
return new FacebookCommentSummary {
Id = obj.GetString("id"),
From = obj.GetObject("from", FacebookObject.Parse),
Message = obj.GetString("message"),
MessageTags = obj.GetArray("message_tags", FacebookMessageTag.Parse),
CreatedTime = obj.GetDateTime("created_time"),
Likes = obj.HasValue("likes") ? obj.GetInt("likes") : 0
};
}
示例13: Parse
public static TwitterException Parse(JsonObject obj) {
// TODO: Does this mess up the stack trace?
if (obj.HasValue("errors") && obj.Dictionary["errors"] is ArrayList) {
obj = obj.GetArray("errors").GetObject(0);
}
throw new TwitterException(obj.GetInt("code"), obj.GetString("message"));
}
示例14: Parse
// Methods
public static LinkedInAccessTokenResponse Parse(JsonObject obj) {
if (obj == null) return null;
if (obj.HasValue("error")) {
throw new Exception(obj.GetString("error") + " " + obj.GetString("error_description"));
}
return new LinkedInAccessTokenResponse {
ExpiresIn = TimeSpan.FromSeconds(obj.GetInt32("expires_in")),
AccessToken = obj.GetString("access_token")
};
}
示例15: Parse
public static FacebookCommentSummary Parse(JsonObject obj) {
// TODO: Should we just return NULL if "obj" is NULL?
if (obj == null) return null;
return new FacebookCommentSummary(obj) {
Id = obj.GetString("id"),
From = obj.GetObject("from", FacebookObject.Parse),
Message = obj.GetString("message"),
MessageTags = obj.GetArray("message_tags", FacebookMessageTag.Parse),
CreatedTime = obj.GetDateTime("created_time"),
Likes = obj.HasValue("likes") ? obj.GetInt32("likes") : 0
};
}