【发布时间】:2015-01-16 12:49:42
【问题描述】:
我正在尝试访问以下 FourSquare NSDictionary 中的“前缀”和“后缀”字符串。在我的 nsobject 中,我尝试了以下操作,但没有成功。有没有简单的方法来访问字符串?我试过了:
venue.photo = v[@"photo"];
venue.photo = v[@"photo"][@"prefix"];
和 NSDictionary 打印:
{
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;
}
【问题讨论】:
-
首先,您打印的是字典,而不是数组。似乎这本字典具有“项目”的价值,它是一个字典数组(在这种情况下只有一个元素)。 items 数组中的第一个字典具有键“page”的字典。页面字典包含键“照片”的字典,其中包含键“前缀”和“后缀”的字符串
-
感谢您指出这一点(我还在学习)。我已经更新了问题并使用了:venue.photo = v[@"specials"][@"items"][@"page"][@"photo"][@"prefix"];但没有运气。
标签: ios json dictionary nsarray foursquare