Web服务调用返回SIGABRT

时间:2014-06-26 17:56:57

标签: ios objective-c xcode web-services

我正在调用一个Web服务,它返回您搜索到的对象的最便宜价格的数据。目前,我正在硬编码网址,只搜索“Logitech”品牌商品。出于某种原因,每当我尝试使用单个响应关键短语如“title”或“id”时,我总是会收到这样的SIGABRT错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKeyedSubscript:]: unrecognized selector sent to instance 0x8dbc2e0'

我的网络服务调用在我的viewDidLoad方法中,如下所示:

  NSString *urlString =@"http://us.api.invisiblehand.co.uk/v1/products?query=Logitech&app_id=dad00cb7&app_key=ab386c3e1b99b58b876f237d77b4211a";

NSURL *url = [NSURL URLWithString:urlString];

NSData *data = [NSData dataWithContentsOfURL:url];

NSMutableArray *itemCallArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];


for (NSDictionary *theItem in itemCallArray)
{
    NSString *titleString = theItem[@"brands"];
    NSLog(@"%@", titleString);


}

我正在把头发拉出来。所有的帮助将不胜感激,并提前感谢您:)

编辑:

当我记录itemCallArray时,我得到了这个(很多东西):

 errors =     (
);
info =     {
    start = 0;
    "total_results" = 4775;
};
results =     (
            {
        asins =             (
        );
        "best_page" =             {
            currency = USD;
            deeplink = "http://www.electronicexpress.com/catalog/20352/Logitech";
            description = "<null>";
            "image_url" = "http://shopping.getinvisiblehand.com/images/no_image_available.png";
            "in_stock" = 1;
            "live_price_url" = "http://api.invisiblehand.co.uk/v1/pages/live_price?url=http%3A%2F%2Fwww.electronicexpress.com%2Fcatalog%2F20352%2FLogitech";
            "original_url" = "http://www.electronicexpress.com/catalog/20352/Logitech";
            pnp = 0;
            price = "<null>";
            "price_confidence" = low;
            region = us;
            "retailer_name" = "Electronicexpress.com";
            title = "Logitech Classic Keyboard  920003199";
        };
        brands =             (
            Logitech
        );
        categories =             (
        );
        eans =             (
        );
        id = cc2565b3d498073b74d6fc2baa9155d3;
        "image_url" = "http://shopping.getinvisiblehand.com/images/no_image_available.png";
        isbns =             (
        );
        models =             (
        );
        mpns =             (
        );
        "number_of_pages" = 1;
        resource = "/products/cc2565b3d498073b74d6fc2baa9155d3";
        title = "Logitech Classic Keyboard  920003199";
        upcs =             (
        );
    },
            {
        asins =             (
        );
        "best_page" =             {
            currency = USD;
            deeplink = "http://www.electronicexpress.com/catalog/17951/Logitech";
            description = "<null>";
            "image_url" = "http://shopping.getinvisiblehand.com/images/no_image_available.png";
            "in_stock" = 1;
            "live_price_url" = "http://api.invisiblehand.co.uk/v1/pages/live_price?url=http%3A%2F%2Fwww.electronicexpress.com%2Fcatalog%2F17951%2FLogitech";
            "original_url" = "http://www.electronicexpress.com/catalog/17951/Logitech";
            pnp = 0;
            price = "<null>";
            "price_confidence" = low;
            region = us;
            "retailer_name" = "Electronicexpress.com";
            title = "Logitech K120 USB Keyboard  920002478";
        };
        brands =             (
            Logitech
        );
        categories =             (
        );
        eans =             (
        );
        id = d46e49d5b7a0f85f5b7e4eaaeded480e;
        "image_url" = "http://shopping.getinvisiblehand.com/images/no_image_available.png";
        isbns =             (
        );
        models =             (
        );
        mpns =             (
        );
        "number_of_pages" = 1;
        resource = "/products/d46e49d5b7a0f85f5b7e4eaaeded480e";
        title = "Logitech K120 USB Keyboard  920002478";
        upcs =             (
        );
    },
            {
        asins =             (
        );
        "best_page" =             {
            currency = USD;
            deeplink = "http://www.electronicexpress.com/catalog/18226/Logitech";
            description = "<null>";
            "image_url" = "http://shopping.getinvisiblehand.com/images/no_image_available.png";
            "in_stock" = 1;
            "live_price_url" = "http://api.invisiblehand.co.uk/v1/pages/live_price?url=http%3A%2F%2Fwww.electronicexpress.com%2Fcatalog%2F18226%2FLogitech";
            "original_url" = "http://www.electronicexpress.com/catalog/18226/Logitech";
            pnp = 0;
            price = "<null>";
            "price_confidence" = low;
            region = us;
            "retailer_name" = "Electronicexpress.com";
            title = "Logitech Z506 5.1 Speakers  980000430";
        };
        brands =             (
            Logitech
        );
        categories =             (
        );
        eans =             (
        );
        id = 7f1b492e40e2a8956475f24f74c0e152;
        "image_url" = "http://shopping.getinvisiblehand.com/images/no_image_available.png";
        isbns =             (
        );
        models =             (
        );
        mpns =             (
        );
        "number_of_pages" = 1;
        resource = "/products/7f1b492e40e2a8956475f24f74c0e152";
        title = "Logitech Z506 5.1 Speakers  980000430";
        upcs =             (
        );
    },
            {
        asins =             (
        );
        "best_page" =             {
            currency = USD;
            deeplink = "http://www.electronicexpress.com/catalog/23904/Logitech";
            description = "<null>";
            "image_url" = "http://shopping.getinvisiblehand.com/images/no_image_available.png";
            "in_stock" = 1;
            "live_price_url" = "http://api.invisiblehand.co.uk/v1/pages/live_price?url=http%3A%2F%2Fwww.electronicexpress.com%2Fcatalog%2F23904%2FLogitech";
            "original_url" = "http://www.electronicexpress.com/catalog/23904/Logitech";
            pnp = 0;
            price = "<null>";
            "price_confidence" = low;
            region = us;
            "retailer_name" = "Electronicexpress.com";
            title = "Logitech M235 Wireless Mouse Light Silver  910002332";
        };
        brands =             (
            Logitech
        );
        categories =             (
        );
        eans =             (
        );
        id = 58fc508d545168dccf81f93bb6070ac3;
        "image_url" = "http://shopping.getinvisiblehand.com/images/no_image_available.png";
        isbns =             (
        );
        models =             (
        );
        mpns =             (
        );
        "number_of_pages" = 1;
        resource = "/products/58fc508d545168dccf81f93bb6070ac3";
        title = "Logitech M235 Wireless Mouse Light Silver  910002332";
        upcs =             (
        );
    },
            {
        asins =             (
        );
        "best_page" =             {
            currency = USD;
            deeplink = "http://www.electronicexpress.com/catalog/23916/Logitech";
            description = "<null>";
            "image_url" = "http://shopping.getinvisiblehand.com/images/no_image_available.png";
            "in_stock" = 1;
            "live_price_url" = "http://api.invisiblehand.co.uk/v1/pages/live_price?url=http%3A%2F%2Fwww.electronicexpress.com%2Fcatalog%2F23916%2FLogitech";
            "original_url" = "http://www.electronicexpress.com/catalog/23916/Logitech";
            pnp = 0;
            price = "<null>";
            "price_confidence" = low;
            region = us;
            "retailer_name" = "Electronicexpress.com";
            title = "Logitech Wireless Combo Mk520 With Keyboard and Laser Mouse   920002553";
        };
        brands =             (
            Logitech
        );
        categories =             (
        );
        eans =             (
        );
        id = ae530f45af7ac34207bd9a44406afa98;
        "image_url" = "http://shopping.getinvisiblehand.com/images/no_image_available.png";
        isbns =             (
        );
        models =             (
        );
        mpns =             (
        );
        "number_of_pages" = 1;
        resource = "/products/ae530f45af7ac34207bd9a44406afa98";
        title = "Logitech Wireless Combo Mk520 With Keyboard and Laser Mouse   920002553";
        upcs =             (
        );
    },
            {
        asins =             (
        );
        "best_page" =             {
            currency = USD;
            deeplink = "http://www.electronicexpress.com/catalog/16215/Logitech";
            description = "<null>";
            "image_url" = "http://shopping.getinvisiblehand.com/images/no_image_available.png";
            "in_stock" = 1;
            "live_price_url" = "http://api.invisiblehand.co.uk/v1/pages/live_price?url=http%3A%2F%2Fwww.electronicexpress.com%2Fcatalog%2F16215%2FLogitech";
            "original_url" = "http://www.electronicexpress.com/catalog/16215/Logitech";
            pnp = 0;
            price = "<null>";
            "price_confidence" = low;
            region = us;
            "retailer_name" = "Electronicexpress.com";
            title = "Logitech LS21 2.1 Stereo Speaker System  980000058";
        };
        brands =             (
            Logitech
        );
        categories =             (
        );
        eans =             (
        );
        id = ad59cd583a1b88c782f8af77e6d71494;
        "image_url" = "http://shopping.getinvisiblehand.com/images/no_image_available.png";
        isbns =             (
        );
        models =             (
        );
        mpns =             (
        );
        "number_of_pages" = 1;
        resource = "/products/ad59cd583a1b88c782f8af77e6d71494";
        title = "Logitech LS21 2.1 Stereo Speaker System  980000058";
        upcs =             (
        );
    },
            {
        asins =             (
        );
        "best_page" =             {
            currency = USD;
            deeplink = "http://www.electronicexpress.com/catalog/16216/Logitech";
            description = "<null>";
            "image_url" = "http://shopping.getinvisiblehand.com/images/no_image_available.png";
            "in_stock" = 1;
            "live_price_url" = "http://api.invisiblehand.co.uk/v1/pages/live_price?url=http%3A%2F%2Fwww.electronicexpress.com%2Fcatalog%2F16216%2FLogitech";
            "original_url" = "http://www.electronicexpress.com/catalog/16216/Logitech";
            pnp = 0;
            price = "<null>";
            "price_confidence" = low;
            region = us;
            "retailer_name" = "Electronicexpress.com";
            title = "Logitech Compact 25Watt 2.1 Speaker System  980000382";
        };
        brands =             (
            Logitech
        );
        categories =             (
        );
        eans =             (
        );
        id = 54c5479754c659a2fac08018a4bce795;
        "image_url" = "http://shopping.getinvisiblehand.com/images/no_image_available.png";
        isbns =             (
        );
        models =             (
        );
        mpns =             (
        );
        "number_of_pages" = 1;
        resource = "/products/54c5479754c659a2fac08018a4bce795";
        title = "Logitech Compact 25Watt 2.1 Speaker System  980000382";
        upcs =             (
        );
    },
            {
        asins =             (
        );
        "best_page" =             {
            currency = USD;
            deeplink = "http://www.electronicexpress.com/catalog/22841/Logitech";
            description = "<null>";
            "image_url" = "http://shopping.getinvisiblehand.com/images/no_image_available.png";
            "in_stock" = 1;
            "live_price_url" = "http://api.invisiblehand.co.uk/v1/pages/live_price?url=http%3A%2F%2Fwww.electronicexpress.com%2Fcatalog%2F22841%2FLogitech";
            "original_url" = "http://www.electronicexpress.com/catalog/22841/Logitech";
            pnp = 0;
            price = "<null>";
            "price_confidence" = low;
            region = us;
            "retailer_name" = "Electronicexpress.com";
            title = "Logitech Z130 Compact Laptop Speakers   980000417";
        };
        brands =             (
            Logitech
        );
        categories =             (
        );
        eans =             (
        );
        id = 7218f2482c0b4f40cf89d57feabb8c58;
        "image_url" = "http://shopping.getinvisiblehand.com/images/no_image_available.png";
        isbns =             (
        );
        models =             (
        );
        mpns =             (
        );
        "number_of_pages" = 1;
        resource = "/products/7218f2482c0b4f40cf89d57feabb8c58";
        title = "Logitech Z130 Compact Laptop Speakers   980000417";
        upcs =             (
        );
    },
            {
        asins =             (
        );
        "best_page" =             {
            currency = USD;
            deeplink = "http://www.newegg.com/Product/Product.aspx?Item=N82E16826104828";
            description = "<null>";
            "image_url" = "http://shopping.getinvisiblehand.com/images/no_image_available.png";
            "in_stock" = 1;
            "live_price_url" = "http://api.invisiblehand.co.uk/v1/pages/live_price?url=http%3A%2F%2Fwww.newegg.com%2FProduct%2FProduct.aspx%3FItem%3DN82E16826104828";
            "original_url" = "http://www.newegg.com/Product/Product.aspx?Item=N82E16826104828";
            pnp = 0;
            price = "<null>";
            "price_confidence" = low;
            region = us;
            "retailer_name" = "Newegg.com";
            title = "Logitech Corded Mouse M318e";
        };
        brands =             (
            Logitech
        );
        categories =             (
        );
        eans =             (
        );
        id = b5ccd2875b684f2209b2972ad85ab529;
        "image_url" = "http://shopping.getinvisiblehand.com/images/no_image_available.png";
        isbns =             (
        );
        models =             (
        );
        mpns =             (
        );
        "number_of_pages" = 1;
        resource = "/products/b5ccd2875b684f2209b2972ad85ab529";
        title = "Logitech Corded Mouse M318e";
        upcs =             (
        );
    },
            {
        asins =             (
        );
        brands =             (
        );
        categories =             (
        );
        eans =             (
        );
        id = 65e25398341ecdca6c54787cf1f3e5d6;
        isbns =             (
        );
        models =             (
        );
        mpns =             (
        );
        "number_of_pages" = 0;
        resource = "/products/65e25398341ecdca6c54787cf1f3e5d6";
        title = "<null>";
        upcs =             (
        );
    }
);

}

1 个答案:

答案 0 :(得分:1)

看起来您的数据源并不完全符合您的想法。根对象似乎是一个字典,包含结果数组作为其键之一。我会尝试这样做。

NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSArray *itemCallArray = [NSArray arrayWithArray:dataDictionary[@"results"]];