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


C# JsonObject.HasValue方法代码示例

本文整理汇总了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")
            };
        
        }
开发者ID:EmilMoe,项目名称:Skybrud.Social,代码行数:62,代码来源:YouTubeVideoStatus.cs

示例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");

        }
开发者ID:jesperordrup,项目名称:Skybrud.Social,代码行数:55,代码来源:InstagramResponse.cs

示例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")
     };
 }
开发者ID:jesperordrup,项目名称:Skybrud.Social,代码行数:14,代码来源:FacebookEvent.cs

示例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;

        }
开发者ID:jesperordrup,项目名称:Skybrud.Social,代码行数:39,代码来源:AnalyticsDataResponse.cs

示例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
            };
        
        }
开发者ID:EmilMoe,项目名称:Skybrud.Social,代码行数:35,代码来源:FacebookDebugTokenData.cs

示例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)
     };
 }
开发者ID:jesperordrup,项目名称:Skybrud.Social,代码行数:12,代码来源:FacebookFeedResponse.cs

示例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")
     };
 }
开发者ID:jesperordrup,项目名称:Skybrud.Social,代码行数:17,代码来源:FacebookMeResponse.cs

示例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"))
     };
 
 }
开发者ID:jesperordrup,项目名称:Skybrud.Social,代码行数:9,代码来源:FacebookPhotosResponse.cs

示例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")
     };
 }
开发者ID:jesperordrup,项目名称:Skybrud.Social,代码行数:10,代码来源:FacebookEventSummary.cs

示例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
            );

        }
开发者ID:jesperordrup,项目名称:Skybrud.Social,代码行数:10,代码来源:FacebookException.cs

示例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,
     };
 }
开发者ID:EmilMoe,项目名称:Skybrud.Social,代码行数:23,代码来源:FacebookApp.cs

示例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
     };
 }
开发者ID:jesperordrup,项目名称:Skybrud.Social,代码行数:10,代码来源:FacebookCommentSummary.cs

示例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"));
        
        }
开发者ID:jesperordrup,项目名称:Skybrud.Social,代码行数:11,代码来源:TwitterException.cs

示例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")
            };
        }
开发者ID:EmilMoe,项目名称:Skybrud.Social,代码行数:13,代码来源:LinkedInAccessTokenResponse.cs

示例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
     };
 }
开发者ID:EmilMoe,项目名称:Skybrud.Social,代码行数:12,代码来源:FacebookCommentSummary.cs


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