Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Mathieu De Haeck
5,645 PointsPhoto Bombers - Extra Credit
How can i get the "username" value in photo NSDictionary and create a string of it ?
6 Answers
Thomas Nilsen
14,957 PointsAlright. Solved. You gave me the wrong JSON file ;)
NSString *username = [_photo valueForKeyPath:@"caption.from.username"];
Thomas Nilsen
14,957 PointsTry something like this if you do it in photoCell.m and override the setter:
- (void)setPhoto:(NSDictionary *)photo
{
_photo = photo;
NSString *username = [_photo[@"username"] stringValue];
}
Mathieu De Haeck
5,645 PointsThanks for your comment.
However, when i do an NSLog on username the result is (null)
Thomas Nilsen
14,957 PointsThat sounds reasonable, because "_photo" is a dictionary containing JSON. You have to see where in the JSON-file username is displayed. Post a picture of the JSON and I can help you further :)
Mathieu De Haeck
5,645 Points2014-04-26 20:45:34.503 Photo Bombers[13003:60b] {
attribution = "<null>";
caption = "<null>";
comments = {
count = 3;
data = (
{
"created_time" = 1397098608;
from = {
"full_name" = "Trey Williams";
id = 174067169;
"profile_picture" = "http://images.ak.instagram.com/profiles/profile_174067169_75sq_1397881123.jpg";
username = "trey_twill";
};
id = 695235976529659618;
text = "Follow beautiful c: @kittylt22";
},
{
"created_time" = 1397445583;
from = {
"full_name" = JavierNY;
id = 194913800;
"profile_picture" = "http://images.ak.instagram.com/profiles/profile_194913800_75sq_1397527573.jpg";
username = 800javierny;
};
id = 698146609747150841;
text = "Followback?";
},
{
"created_time" = 1398537920;
from = {
"full_name" = "Lauren Turk";
id = 360852000;
"profile_picture" = "http://images.ak.instagram.com/profiles/profile_360852000_75sq_1366837104.jpg";
username = kittylt22;
};
id = 707309801056453943;
text = "#losangeles #models #photowall #fashionista #fashionshow #photoaday #photos #kiss #modeling #photochallenge #clothing #hollywood #fashiondiaries #photobomb #fashionable #photographer #fashionweek #dtla #model #photoshoot #fashionblogger #recycle #shop #desigual #likelikelike #likeforlikes #segue #followfollowfollow #selfie #trocolikes";
}
);
};
"created_time" = 1396340109;
filter = "Lo-fi";
id = "688873223065912684_360852000";
images = {
"low_resolution" = {
height = 306;
url = "http://origincache-ash.fbcdn.net/924915_231566267038703_1440352486_a.jpg";
width = 306;
};
"standard_resolution" = {
height = 640;
url = "http://origincache-ash.fbcdn.net/924915_231566267038703_1440352486_n.jpg";
width = 640;
};
thumbnail = {
height = 150;
url = "http://origincache-ash.fbcdn.net/924915_231566267038703_1440352486_s.jpg";
width = 150;
};
};
likes = {
count = 62;
data = (
{
"full_name" = "Jessica Sarah";
id = 249699288;
"profile_picture" = "http://images.ak.instagram.com/profiles/profile_249699288_75sq_1397935911.jpg";
username = "jess__bolton";
},
{
"full_name" = "Randy-Cheyn James";
id = 216910121;
"profile_picture" = "http://images.ak.instagram.com/profiles/profile_216910121_75sq_1393290733.jpg";
username = bassandlazers;
},
{
"full_name" = "\U2661 P A U L A \U2022 Germany";
id = 692031895;
"profile_picture" = "http://images.ak.instagram.com/profiles/profile_692031895_75sq_1390043500.jpg";
username = paulalachanceuse;
},
{
"full_name" = Christina;
id = 1242563185;
"profile_picture" = "http://images.ak.instagram.com/profiles/profile_1242563185_75sq_1396694799.jpg";
username = wrimet614;
}
);
};
link = "http://instagram.com/p/mPXovsH0Vs/";
location = {
latitude = "47.565304055";
longitude = "7.600623965";
};
tags = (
shop,
likeforlikes,
losangeles,
segue,
followfollowfollow,
models,
dtla,
fashionista,
trocolikes,
fashionshow,
desigual,
photos,
kiss,
modeling,
photochallenge,
clothing,
model,
photoaday,
fashiondiaries,
photobomb,
fashionable,
photographer,
fashionweek,
likelikelike,
photowall,
recycle,
hollywood,
photoshoot,
fashionblogger,
selfie
);
type = image;
user = {
bio = "";
"full_name" = "Lauren Turk";
id = 360852000;
"profile_picture" = "http://images.ak.instagram.com/profiles/profile_360852000_75sq_1366837104.jpg";
username = kittylt22;
website = "";
};
"user_has_liked" = 0;
"users_in_photo" = (
);
}
Thomas Nilsen
14,957 Points- (void)setPhoto:(NSDictionary *)photo
{
_photo = photo;
NSString *username = [_photo valueForKeyPath:@"data.from.username"]
}
or
- (void)setPhoto:(NSDictionary *)photo
{
_photo = photo;
NSString *username = [_photo valueForKeyPath:@"data.username"]
}
Mathieu De Haeck
5,645 PointsIts still (null)
Thomas Nilsen
14,957 PointsDo you mind sending me your project, so I can solve it? :) My answer is based on the viewController looking a specific way
Mathieu De Haeck
5,645 PointsThanks
Mathieu De Haeck
5,645 PointsMathieu De Haeck
5,645 Pointsoh... sorry :s
Thanks for the help, i really appreciate it ;) !