Ios 无法在FourSquare API中访问NSDictionary密钥
我正在尝试访问以下FourSquare NSDictionary中的前缀和后缀字符串。在我的nsobject中,我尝试了以下方法,但没有成功。有没有一种简单的方法来访问字符串?我试过:Ios 无法在FourSquare API中访问NSDictionary密钥,ios,json,dictionary,nsarray,foursquare,Ios,Json,Dictionary,Nsarray,Foursquare,我正在尝试访问以下FourSquare NSDictionary中的前缀和后缀字符串。在我的nsobject中,我尝试了以下方法,但没有成功。有没有一种简单的方法来访问字符串?我试过: venue.photo = v[@"photo"]; venue.photo = v[@"photo"][@"prefix"]; 词典会打印: { categories = ( { icon = {
venue.photo = v[@"photo"];
venue.photo = v[@"photo"][@"prefix"];
词典会打印:
{
categories = (
{
icon = {
prefix = "https://ss3.4sqi.net/img/categories_v2/arts_entertainment/movietheater_";
suffix = ".png";
};
id = 4bf58dd8d48988d17f941735;
name = "Movie Theater";
pluralName = "Movie Theaters";
primary = 1;
shortName = "Movie Theater";
}
);
contact = {
formattedPhone = "(844) 462-7342";
phone = 8444627342;
twitter = regalmovies;
};
events = {
count = 9;
summary = "9 movies";
};
hasMenu = 1;
hereNow = {
count = 2;
groups = (
{
count = 2;
items = (
);
name = "Other people here";
type = others;
}
);
summary = "2 people are checked in here";
};
id = 4a2aac37f964a52034961fe3;
location = {
address = "1471 W Webster Ave";
cc = US;
city = Chicago;
country = "United States";
formattedAddress = (
"1471 W Webster Ave",
"Chicago, IL 60614",
"United States"
);
lat = "41.92149057";
lng = "-87.66487751";
postalCode = 60614;
state = IL;
};
menu = {
anchor = "View Menu";
label = Menu;
mobileUrl = "https://foursquare.com/v/4a2aac37f964a52034961fe3/device_menu";
type = Menu;
url = "https://foursquare.com/v/regal-webster-place-11/4a2aac37f964a52034961fe3/menu";
};
name = "Regal Webster Place 11";
referralId = "v-1416373439";
specials = {
count = 1;
items = (
{
description = "";
icon = default;
id = 50355f96d86cbef3478adc65;
interaction = {
entryUrl = "https://foursquare.com/device/specials/50355f96d86cbef3478adc65?venueId=4a2aac37f964a52034961fe3";
};
message = "Join us for Deal Days! ALL DAY Tuesday enjoy $6.50 tickets.";
page = {
bio = "";
contact = {
twitter = regalmovies;
};
firstName = "Regal Cinemas";
followers = {
count = 12203;
groups = (
);
};
gender = none;
homeCity = "Knoxville, TN";
id = 12864010;
photo = {
prefix = "https://irs0.4sqi.net/img/user/";
suffix = "/DMGZGZVXT3NVLKNP.jpg";
};
tips = {
count = 347;
};
type = chain;
};
provider = foursquare;
redemption = webview;
state = unlocked;
title = Special;
type = frequency;
unlocked = 1;
}
);
};
stats = {
checkinsCount = 23578;
tipCount = 56;
usersCount = 10220;
};
storeId = Chicago;
verified = 1;
}
下面的代码应该可以工作-
NSArray *itemsArray=(NSArray *)venue[@"items"];
for (NSDictionary *specialDictionary in itemsArray) {
NSDictionary *pageDictionary=(NSDictionary *)specialDictionary[@"page"];
NSDictionary *photoDictionary=(NSDictionary *)pageDictionary[@"photo"];
NSString *prefix=(NSString *)photoDictionary[@"prefix"];
NSString *suffix=(NSString *)photoDictionary[@"suffix"];
// Do something with prefix and suffix
}
请注意,关键项目中有一个小括号,这一行
items = ( <----
{
description = "";
icon = default;
id = 50355f96d86cbef3478adc65;
interaction = {
首先,您打印的是字典,而不是数组。这个字典似乎有items的值,在本例中,items是一个包含一个元素的字典数组。items数组中的第一个字典具有密钥页的字典。页面字典包含一个关键图片字典,其中包含关键前缀字符串和后缀,用于指出我仍在学习。我更新了问题并使用了:vitune.photo=v[@specials][@items][@page][@photo][@prefix];但没有运气。我尝试了一下,但出现了错误:“NSRangeException”,原因:“***-[\uu NSArrayI objectAtIndex:]:索引0超出空数组的界限”您可以先检查项目的大小NSLog@size:%d,v[@specials][@items]。大小;猜测items数组有时可能是空的??谢谢,但我得到了错误“读取字典元素的预期方法在“FSVenue”类型的对象上找不到”。在研究之后,我是否要在我的“FSVenue”对象中添加objectforkeydsubscript:?哪个对象是FSVenue?看起来你没有一本普通的词典,但你正在使用一些库?你正在使用的图书馆的URL是什么。它是FourSquare场馆/搜索API-。这就是您所指的吗?不,错误消息中显示的是什么类型的对象?它似乎是一个FSVenue,而不是您将从JSONParser返回的普通NSDictionary。您是否正在使用某个框架或库与API进行交互?您是对的,地点是FSVINCE,对此感到困惑,深表歉意。我使用的是Constantine的github,如果这回答了您的URL问题,那么调用将使用NSURLRequest。
venue.photo = v[@"specials"][@"items"][0][@"page"][@"photo"][@"prefix"];