gpt4 book ai didi

ios - Web 服务调用返回 SIGABRT

转载 作者:行者123 更新时间:2023-11-29 12:42:56 24 4
gpt4 key购买 nike

我正在调用一个网络服务,该服务返回您搜索的对象的最低价格数据。现在,我正在对 URL 进行硬编码以仅搜索“Logitech”品牌商品。出于某种原因,每当我尝试使用像“标题”或“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 = (
);
}
);

最佳答案

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

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

关于ios - Web 服务调用返回 SIGABRT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24437160/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com