如何在此响应中检查图像是否包含数据

时间:2015-08-05 09:27:55

标签: ios

这是我的回复API。图像数据动态变化,一次有更多图像,或者一次没有图像。我检查为([image_array count] == 0)但由于空数组导致应用程序崩溃 错误

reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(
    0   CoreFoundation                      0x0243edf6 __exceptionPreprocess + 182

API响应

{
    response =     {
        Details =         {
            ID = 4;
            address = "";
            ancestors =             (
            );
            "comment_count" = 0;
            "comment_status" = closed;
            description = "";
            "description_pt" = "";
            duration = 2;
            "event_address" = "";
            "event_location" = ",";
            "event_location_option" = "";
            "event_place_address" = "";
            "event_place_email" = "";
            "event_place_location" = "";
            "event_place_phone" = "";
            "event_place_website" = "";
            filter = raw;
            guid = "";
            images =             (
            );
            "like_count" = 0;
            "like_status" = FALSE;
            location = "";
            "menu_order" = 0;
            "ping_status" = closed;
            pinged = "";
            "place_event_count" = "";
            "place_event_id" = "";
            "place_id" = "";
            "post_author" = 5;
            "post_category" =             (
            );
            "post_content" = "";
            "post_content_filtered" = "";
            "post_date" = "2015-07-31 ";
            "post_date_gmt" = "2015-07-31 ";
            "post_excerpt" = "";
            "post_mime_type" = "";
            "post_modified" = "2015-07-31 ";
            "post_modified_gmt" = "2015-07-31 ";
            "post_name" = 48;
            "post_parent" = 0;
            "post_password" = "";
            "post_status" = publish;
            "post_title" = "";
            "post_type" = events;
            "tags_input" =             (
            );
            time = "17:50:30";
            title = "";
            "title_pt" = "";
            "to_ping" = "";
            video = "";
            website = "";
        };
        Message = "Post Details";
        httpCode = 10;
    };
}

1 个答案:

答案 0 :(得分:0)

像这样检查

NSArray *array = [data valueForKey@"images"];
if (![array isKindOfClass:[NSArray class]]) {
    //its not array or have null value
}else{
    //its real array
}

它会正常工作

相关问题