I want to parse a array of json dictionary which is returned to me using the method flickr.photosets.getlist.I am using objectiveFlickr api.
This is my json
"_text" = "\n\n";
photosets = {
"_text" = "\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\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t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n";
cancreate = 1;
page = 1;
pages = 1;
perpage = 871;
photoset = (
{
"_text" = "\n\t\t\n\t\t\n\t";
"can_comment" = 1;
"count_comments" = 0;
"count_views" = 0;
"date_create" = 1403859842;
"date_update" = 0;
description = {
"_text" = "Uploaded from my iPhone/iPod Touch";
};
farm = 6;
id = 72157645380087391;
"needs_interstitial" = 0;
photos = 1;
primary = 14514940751;
secret = ebc107d841;
server = 5237;
title = {
"_text" = banjara;
};
videos = 0;
"visibility_can_see_set" = 1;
},
{
"_text" = "\n\t\t\n\t\t\n\t";
"can_comment" = 1;
"count_comments" = 0;
"count_views" = 0;
"date_create" = 1403849913;
"date_update" = 0;
description = {
"_text" = "Uploaded from my iPhone/iPod Touch";
};
farm = 4;
id = 72157645380777662;
"needs_interstitial" = 0;
photos = 1;
primary = 14516264624;
secret = 70097bb15c;
server = 3867;
title = {
"_text" = iuggjkd;
};
videos = 0;
"visibility_can_see_set" = 1;
}
);
};
I am stuck in this for hours.Can u suggest me how to deal with this.
Thanks for the reply
Try doing something like this. This is not the exact solution and you'll have to work around your way.
NSString *link = [NSString stringWithFormat:#"yourServiceURL"];
NSString *encdLink = [link stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url=[NSURL URLWithString:encdLink];
NSData *response = [NSData dataWithContentsOfURL:url];
NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:response options: NSJSONReadingMutableContainers error: &error];
Now you have your data in the array and extract it out using objectForKey or valueForKey.You can use NSDictionary or NSArray as per your requirement.
This is what I am doing to fetch images from JSON and showing in my app. Firstly get the array from the above code. Then extract out the image content like this :
_demoArray = [json valueForKey:#"yourKeyField"];
Now you have the values in your demoArray.
Hope this helps.
Related
This question already has answers here:
Sort NSArray of NSDictionaries by string date in key?
(2 answers)
Closed 7 years ago.
I have a NSArray with the following data;
(
{
3d = 0;
cinemaId = 9;
displayDate = "2015-08-19";
end = "2015-08-20T00:14:00+02:00";
hallIsLarge = 0;
hfr = 0;
id = 1505511;
imax = 0;
movieId = 19623;
nl = 0;
ov = 1;
showId = 24422279;
specialCode = "<null>";
specialId = "<null>";
start = "2015-08-19T22:00:00+02:00";
status = 3;
vip = 0;
},
{
3d = 1;
cinemaId = 10;
displayDate = "2015-08-19";
end = "2015-08-20T00:25:00+02:00";
hallIsLarge = 0;
hfr = 0;
id = 1504415;
imax = 0;
movieId = 16936;
nl = 0;
ov = 1;
showId = 24436778;
specialCode = "<null>";
specialId = "<null>";
start = "2015-08-19T22:05:00+02:00";
status = 3;
vip = 0;
},
{
3d = 0;
cinemaId = 9;
displayDate = "2015-08-19";
end = "2015-08-20T00:08:00+02:00";
hallIsLarge = 0;
hfr = 0;
id = 1506419;
imax = 0;
movieId = 21068;
nl = 0;
ov = 1;
showId = 24422340;
specialCode = "<null>";
specialId = "<null>";
start = "2015-08-19T22:10:00+02:00";
status = 3;
vip = 0;
},
{
3d = 0;
cinemaId = 10;
displayDate = "2015-08-19";
end = "2015-08-20T00:08:00+02:00";
hallIsLarge = 0;
hfr = 0;
id = 1504237;
imax = 0;
movieId = 21068;
nl = 0;
ov = 1;
showId = 24436788;
specialCode = "<null>";
specialId = "<null>";
start = "2015-08-19T22:10:00+02:00";
status = 3;
vip = 0;
}
)
I want to sort the dictionary by the key "start". To do this, I have:
NSSortDescriptor *brandDescriptor = [[NSSortDescriptor alloc] initWithKey:#"start" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:brandDescriptor];
programmering = [programmering sortedArrayUsingDescriptors:sortDescriptors];
In the code above is 'programming' the array, but it seems not to work.
What can I do to make this work?
Thanks for your help in advance.
Yes programming is an array, that you want to be sorting, in your code snippet.
The key by which you are trying to sort is a date string/ nsdate object. Hence you need to compare by nsdate and sort.
Here assuming your array is the array of dictionaries, here yourArrayOfDicts
NSArray *sortedArray = [yourArrayOfDicts sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
//You will probably have to use nsdateformatter to convert your date string to valid nsdate objects
// I am assuming you have the nsdate object here as the start key
// if not make sure to convert it to a nsdate object for this to work
NSDate *firstDate = obj1[#"start"];
NSDate *secondDate = obj2[#"start"];
return [firstDate compare:secondDate];
}];
This should give the sortedArray sorted.
I can get the location information from photo album on ios, but I would like to access image location (latitude and longitude) when I took a photo.
so this is image finished event
public override void FinishedPickingMedia(UIImagePickerController picker, NSDictionary info)
{
//UIImagePickerController.ReferenceUrl
var originalImage = new NSString("UIImagePickerControllerOriginalImage");
var image = (UIImage)info[originalImage];
foreach (var item in info)
Console.WriteLine(item.Key + " " + item.Value);
image.SaveToPhotosAlbum(delegate(UIImage img, NSError err)
{
Console.WriteLine("Saved!");
});
_dp.DismissModalViewController(true);
OnImageChoosed(image);
}
}
and in info dictionary, i can see those properties
UIImagePickerControllerMediaMetadata {
DPIHeight = 72;
DPIWidth = 72;
Orientation = 6;
"{Exif}" = {
ApertureValue = "2.27500704749987";
BrightnessValue = "5.267792568433492";
ColorSpace = 1;
DateTimeDigitized = "2015:07:08 14:24:15";
DateTimeOriginal = "2015:07:08 14:24:15";
ExposureBiasValue = 0;
ExposureMode = 0;
ExposureProgram = 2;
ExposureTime = "0.008333333333333333";
FNumber = "2.2";
Flash = 24;
FocalLenIn35mmFilm = 29;
FocalLength = "4.15";
ISOSpeedRatings = (
40
);
LensMake = Apple;
LensModel = "iPhone 6 back camera 4.15mm f/2.2";
LensSpecification = (
"4.15",
"4.15",
"2.2",
"2.2"
);
MeteringMode = 5;
PixelXDimension = 3264;
PixelYDimension = 2448;
SceneType = 1;
SensingMethod = 2;
ShutterSpeedValue = "6.908853996279415";
SubjectArea = (
1631,
1223,
1795,
1077
);
SubsecTimeDigitized = 927;
SubsecTimeOriginal = 927;
WhiteBalance = 0;
};
"{MakerApple}" = {
1 = 2;
14 = 0;
2 = <af001d01 9001ed01 9e011f01 70001500 41000d00 0a001000 12000900 0e000e00 b5003201 ae01f701 9b010401 5b001400 47002300 11001500 15000800 0d000d00 c2005501 eb014402 c901d900 67002400 3d002400 0f000b00 08000900 0d000d00 f1009201 30028e02 ff01b200 51000e00 43000e00 0d000e00 0d000d00 0c000b00 2d02b302 f802e902 26029700 80005600 5e000e00 0b000a00 09000900 0a000900 88039703 87033503 3c028300 44001100 45001100 0c000d00 0d000d00 0d000a00 b903b103 97034703 44027700 3e001000 38001000 0d000d00 0e000d00 0d000a00 a4039f03 87031503 22026d00 38000b00 34001000 0d001000 12000b00 0b000900 7b036a03 1d039c02 e2016400 37000e00 32001100 0d000a00 0a000600 07000700 c0029a02 4e02fb01 79015b00 36000e00 31001200 0c000900 0a000700 0c000b00 8b017801 4b013501 01015500 34000a00 30000900 06000c00 0e000800 14001000 b9001a00 34008a00 bd005000 2f000c00 2f000c00 0c000b00 0d000500 07000700 60000e00 0c002400 8f004b00 2f000a00 2d000f00 0e000700 07000700 0b000a00 47000b00 0a000b00 3d003300 28000a00 2b000a00 06000a00 0e000700 12001000 29000a00 09000a00 25003b00 2a000e00 2a000c00 0b000e00 11000700 0a000c00 27000a00 08000a00 0f003f00 3f001b00 31000d00 0e000700 07000700 0a000800>;
3 = {
epoch = 0;
flags = 1;
timescale = 1000000000;
value = 401611073225666;
};
4 = 1;
5 = 128;
6 = 119;
7 = 1;
8 = (
"0.01929908",
"-0.713904",
"-0.7083461"
);
};
"{TIFF}" = {
DateTime = "2015:07:08 14:24:15";
Make = Apple;
Model = "iPhone 6";
Software = "8.3";
XResolution = 72;
YResolution = 72;
};
As you see there is no location information. Well I tried to save image on local after get the location informatin but didnt work.
As I understand, If I can get path of the image which saved to the photo album, I can got
var path = args.Info[UIImagePickerController.ReferenceUrl].ToString();
refeenceURL like above and after I can get the location.. But i dont know how to get path of the newly saved image.
P.S.: I used Xamarin.iOS with C# but doesnt matter if you provide objective C or swift code.
I have an old snippet that I've never used (its an NSMutableDictionary category), because in the app I've used AVFoundation, but it worth a try. Credits to the creator of that code Gustavo Ambrozio.
Since is really old you should adapt for ARC compatibility.
- (id)initWithInfoFromImagePicker:(NSDictionary *)info {
if ((self = [self init])) {
// Key UIImagePickerControllerReferenceURL only exists in iOS 4.1
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 4.1f) {
NSURL* assetURL = nil;
if ((assetURL = [info objectForKey:UIImagePickerControllerReferenceURL])) {
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:assetURL
resultBlock:^(ALAsset *asset) {
NSDictionary *metadata = asset.defaultRepresentation.metadata;
[self addEntriesFromDictionary:metadata];
}
failureBlock:^(NSError *error) {
}];
[library autorelease];
}
else {
NSDictionary *metadata = [info objectForKey:UIImagePickerControllerMediaMetadata];
if (metadata)
[self addEntriesFromDictionary:metadata];
}
}
}
return self;
}
I am trying to extract the dependentLocality information that is returned in a CLPlacemark object. The data (anonymized) looks like
{
"cache_control" = CACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
ttl = 15768000;
type = "COMPONENT_TYPE_ADDRESS";
value = (
{
address = {
"known_accuracy" = POINT;
"localized_address" = (
{
address = {
formattedAddressLine = (
"111 Some St",
"Brooklyn, NY 11111-1111",
"United States"
);
structuredAddress = {
administrativeArea = "New York";
administrativeAreaCode = NY;
areaOfInterest = (
"Long Island"
);
country = "United States";
countryCode = US;
dependentLocality = (
"Bedford Stuyvesant",
Brooklyn
);
fullThoroughfare = "111 Some St";
geoId = (
);
locality = "New York";
postCode = 11206;
postCodeExtension = 1111;
postCodeFull = "11111-1111";
subAdministrativeArea = Kings;
subLocality = Brooklyn;
subThoroughfare = 111;
thoroughfare = "Some St";
};
};
locale = "en_US";
}
);
};
}
);
"values_available" = 1;
version = 7;
"version_domain" = (
apple,
revgeo,
US
);
},
I can't access the contents (other than through Apple's structuredAddress property, which doesn't contain what I want). I want to extract "Bedford Stuyvesant", Brooklyn" from what's above, for instance. Have tried numerous ways around this, but eg. casting the placemark to an NSDictionary fails. Any help would be greatly appreciated!
Maybe you can do some string processing to extract dependentLocality from your placemark.description. But why don't you just use placemark.subLocality property?
NSString *geoMapItem = placemark.description;
NSRange start = [geoMapItem rangeOfString:#"dependentLocality"];
NSRange end = [geoMapItem rangeOfString:#")" options:NSCaseInsensitiveSearch range:NSMakeRange(start.location, 1000)];
NSString *dataString = [geoMapItem substringWithRange:NSMakeRange(start.location, end.location - start.location + end.length)];
dataString = [dataString stringByReplacingOccurrencesOfString:#"\n" withString:#""];
dataString = [dataString stringByReplacingOccurrencesOfString:#" " withString:#""];
dataString = [dataString stringByReplacingOccurrencesOfString:#"\"" withString:#""];
start = [dataString rangeOfString:#"("];
end = [dataString rangeOfString:#")"];
NSString *arrayString = [dataString substringWithRange:NSMakeRange(start.location + 1, end.location - start.location - 1)];
NSArray *array = [arrayString componentsSeparatedByString:#","];
I'm attempting to read the metadata produced by a UIImage when shot from the UIImagePicker, and I'm having some trouble.
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
// get the metadata
NSDictionary *imageMetadata = [info objectForKey:UIImagePickerControllerMediaMetadata];
NSLog (#"imageMetaData %#",imageMetadata);
This successfully prints the metadata dictionary to NSLog.
The issue I'm having is that I would like to access specific indices of the dictionary (such as FNumber, ISO, etc.) and print them to specific labels, but I can't figure out how to access the individual data.
Here is what I have tried so far to pull the data, but it doesn't seem to find the key (it returns as NULL):
NSLog(#"ISO: %#", imageMetadata[#"ISOSpeedRatings"]);
Based off of what NSLog prints for the dictionary, it seems as if there may be dictionaries within the dictionary, and that's what's throwing me off.
Here's what gets printed for the metadata:
imageMetaData {
DPIHeight = 72;
DPIWidth = 72;
Orientation = 6;
"{Exif}" = {
ApertureValue = "2.27500704749987";
BrightnessValue = "-0.6309286396300304";
ColorSpace = 1;
DateTimeDigitized = "2015:04:01 10:33:37";
DateTimeOriginal = "2015:04:01 10:33:37";
ExposureBiasValue = 0;
ExposureMode = 0;
ExposureProgram = 2;
ExposureTime = "0.06666666666666667";
FNumber = "2.2";
Flash = 24;
FocalLenIn35mmFilm = 29;
FocalLength = "4.15";
ISOSpeedRatings = (
320
);
LensMake = Apple;
LensModel = "iPhone 6 back camera 4.15mm f/2.2";
LensSpecification = (
"4.15",
"4.15",
"2.2",
"2.2"
);
MeteringMode = 5;
PixelXDimension = 3264;
PixelYDimension = 2448;
SceneType = 1;
SensingMethod = 2;
ShutterSpeedValue = "3.907056515078773";
SubjectArea = (
1631,
1223,
1795,
1077
);
SubsecTimeDigitized = 705;
SubsecTimeOriginal = 705;
WhiteBalance = 0;
};
"{MakerApple}" = {
1 = 2;
14 = 0;
2 = <0f000b00 06000900 04005000 a900b100 b700bb00 c400cd00 cd00a400 b100c700 14000b00 05000900 06000a00 8a00a800 b000b800 c300cb00 c900cd00 b300a600 2f000700 06000700 0a000400 3500a400 ab00b300 bc00c300 cf00d300 b4007f00 3f000700 09000700 0a000700 05007100 a100af00 b500c200 ce00cd00 a9006b00 1f000a00 0b000900 0a000c00 05001e00 9c00aa00 b400c200 cc00d000 d4005700 2b001900 0d001000 10000d00 08000600 5b00a700 b300bf00 cb00d500 e3008600 eb002800 1a001700 14000c00 0b000700 10009400 b100c000 ce00e000 f400bd00 cf013e00 2a001200 17000f00 0d000800 07004200 b100c000 d300e900 fd000401 ff011101 1d000700 16001400 09000700 07000900 8900bf00 d800ec00 07011f01 10021102 39000b00 10001900 0e000800 0a000700 2c00bf00 dd00f400 0b012401 1e023802 1f010d00 07001900 16000c00 0c000800 21007000 c500f400 0a012e01 10022202 01022500 08001000 18001100 0d001800 1601cc00 d100eb00 09012201 fb011002 26020401 0f000700 16001400 3200e801 6001b000 ce00f400 08011601 e1010602 1a020302 23001700 21002300 84009300 9f00ad00 bf00e800 02011401 ca01fc01 19024002 08013d00 3500ca00 7c009200 9e00ab00 c200d700 f8000a01 b401f101 1b024802 28023000 4a007f00 7f008e00 a000b100 bd00d000 ec00fe00>;
3 = {
epoch = 0;
flags = 1;
timescale = 1000000000;
value = 777291330499583;
};
4 = 1;
5 = 128;
6 = 123;
7 = 1;
8 = (
"0.2226092",
"-0.5721548",
"-0.7796207"
);
9 = 275;
};
"{TIFF}" = {
DateTime = "2015:04:01 10:33:37";
Make = Apple;
Model = "iPhone 6";
Software = "8.1.2";
XResolution = 72;
YResolution = 72;
};
}
Is the data I'm looking for within another NSDictionary named Exif? And if so, how do I access it?
#david strauss can you try this once
- (void) saveImage:(UIImage *)imageToSave withInfo:(NSDictionary *)info{
// Get the assets library
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// Get the image metadata (EXIF & TIFF)
NSMutableDictionary * imageMetadata = [[info objectForKey:UIImagePickerControllerMediaMetadata] mutableCopy];
// add GPS data
CLLocation * loc = <•••>; // need a location here
if ( loc ) {
[imageMetadata setObject:[self gpsDictionaryForLocation:loc] forKey:(NSString*)kCGImagePropertyGPSDictionary];
}
ALAssetsLibraryWriteImageCompletionBlock imageWriteCompletionBlock =
^(NSURL *newURL, NSError *error) {
if (error) {
NSLog( #"Error writing image with metadata to Photo Library: %#", error );
} else {
NSLog( #"Wrote image %# with metadata %# to Photo Library",newURL,imageMetadata);
}
};
// Save the new image to the Camera Roll
[library writeImageToSavedPhotosAlbum:[imageToSave CGImage]
metadata:imageMetadata
completionBlock:imageWriteCompletionBlock];
[imageMetadata release];
[library release];
}
The metadata dictionary as you've noticed consists of several dictionaries.
So to answer your question - yes, if you're looking for specific values you can access the inner dictionaries. Also, you'd better use the proper keys from ImageIO constants; for example:
NSLog(#"%#", imageMetadata[(NSString*)kCGImagePropertyExifDictionary][(NSString*)kCGImagePropertyExifISOSpeedRatings]);
Or, you can use a key-path:
NSString *keyPath = [NSString stringWithFormat:#"%#.%#",
(NSString*)kCGImagePropertyExifDictionary, (NSString*)kCGImagePropertyExifISOSpeedRatings];
NSLog(#"%#", [imageMetadata valueForKeyPath:keyPath]);
your all required data is within this dictionary only.
you can use json formatter to see the exact location of your data.
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject: imageMetadata
options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
error:&error];
if (! jsonData) {
NSLog(#"Got an error: %#", error);
} else {
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(#"jsonString: %#", jsonString);
}
after this get the exact location of your data from json
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I'm trying to get the "firstName" , "lastName" , "gender", "homeCity" and "email" from a NSDictionary
but It doesn't work...I have tried the following code:
NSDictionary *userInfo = [fsUser getUserInfo:#"self"];
NSLog(#"userInfo: %#", userInfo);
NSLog(#"name: %#", [userInfo objectForKey:#"firstName"]);
NSLog(#"lastName: %#", [userInfo objectForKey:#"lastName"]);
NSLog(#"gender: %#", [userInfo objectForKey:#"gender"]);
NSLog(#"homeCity: %#", [userInfo objectForKey:#"homeCity"]);
NSLog(#"email: %#", [userInfo objectForKey:#"email"]);
here is my dictionary value...
userInfo: {
userDictionary = {
meta = {
code = 200;
errorDetail = "Please provide an API version to avoid future errors.See http://bit.ly/vywCav";
errorType = deprecated;
};
notifications = (
{
item = {
unreadCount = 0;
};
type = notificationTray;
}
);
response = {
user = {
badges = {
count = 0;
items = (
);
};
bio = "";
checkinPings = off;
checkins = {
count = 0;
};
contact = {
email = "email#email.com";
};
firstName = Name;
following = {
count = 0;
};
friends = {
count = 0;
groups = (
{
count = 0;
items = (
);
name = "Amigos em comum";
type = friends;
},
{
count = 0;
items = (
);
name = "Outros amigos";
type = others;
}
);
};
gender = male;
homeCity = "";
id = 3233312;
lastName = lastName;
lists = {
groups = (
{
count = 1;
items = (
);
type = created;
}
);
};
mayorships = {
count = 0;
items = (
);
};
photo = "https://foursquare.com/img/blank_boy.png";
photos = {
count = 0;
items = (
);
};
pings = 0;
referralId = "u-sdsad";
relationship = self;
requests = {
count = 0;
};
scores = {
checkinsCount = 0;
goal = 50;
max = 0;
recent = 0;
};
tips = {
count = 0;
};
todos = {
count = 0;
};
type = user;
};
};
};
}
Use [userInfo objectForKey:#"userDictionary"] objectForKey:#"response"] objectForKey:#"user"] objectForKey:#"homeCity"].
This is where key-value coding (KVC) comes in handy. You can do (note use of valueForKey::
NSDictionary *userInfo = [fsUser getUserInfo:#"self"];
NSLog(#"userInfo: %#", userInfo);
NSLog(#"name: %#", [userInfo valueForKey:#"response.user.firstName"]);
NSLog(#"lastName: %#", [userInfo valueForKey:#"response.user.lastName"]);
NSLog(#"gender: %#", [userInfo valueForKey:#"response.user.gender"]);
NSLog(#"homeCity: %#", [userInfo valueForKey:#"response.user.homeCity"]);
NSLog(#"email: %#", [userInfo valueForKey:#"response.user.email"]);
But this isn't very efficient since you keep digging deep into the same dictionary. It would be better to do this:
NSDictionary *userInfo = [fsUser getUserInfo:#"self"];
NSDictionary *user = [userInfo valueForKey:#"response.user"];
NSLog(#"userInfo: %#", userInfo);
NSLog(#"name: %#", [user objectForKey:#"firstName"]);
NSLog(#"lastName: %#", [user objectForKey:#"lastName"]);
NSLog(#"gender: %#", [user objectForKey:#"gender"]);
NSLog(#"homeCity: %#", [user objectForKey:#"homeCity"]);
NSLog(#"email: %#", [user objectForKey:#"email"]);
It doesn't work because your userInfo doesn't have such keys.
userInfo has userDictionary, which has meta, notifications and response.
response has user, and user has firstName, lastName etc.
Your top leve is userInfo, but there are "objects" within that as well. You will have to traverse those to get to first name. Something like this will work:
NSLog(#"first name = %#", userInfo[#"userInfo"][#"userDictionary"][#"response"][#"user"][#"firstName"]);