Using that code I'm able to get all the list of array.
Looking a lot of tutorial but I'm not able to get the var called "id" if the "name" isEqual to "Timeline Photos".
Code:
NSArray *feed =[result objectForKey:#"data"];
for (NSDictionary *dict in feed) {
NSLog(#"%#",dict);
}
Result (Example of the first two result):
2015-02-03 13:59:21.246 Project[708:29363] {
"can_upload" = 0;
count = 68;
"cover_photo" = 10200808394440000;
"created_time" = "2011-03-09T17:25:03+0000";
from = {
id = 10204248513160000;
name = "XX XX";
};
id = 1716972770000;
link = "https://www.facebook.com/album.php?..";
name = "Mobile Uploads";
privacy = everyone;
type = mobile;
"updated_time" = "2015-01-31T13:28:32+0000";
}
2015-02-03 13:59:21.247 Project[708:29363] {
"can_upload" = 0;
count = 11;
"cover_photo" = 4383404270000;
"created_time" = "2010-02-15T15:50:30+0000";
from = {
id = 10204248513160000;
name = "XX XX";
};
id = 1267183610000;
link = "https://www.facebook.com/album.php?...";
name = "Timeline Photos";
privacy = everyone;
type = wall;
"updated_time" = "2015-01-28T18:26:52+0000";
}
Try this:
NSArray *feed =[result objectForKey:#"data"];
for (NSDictionary *dict in feed) {
if ([dict[#"name"] isEqualToString:#"Timeline Photos"])
NSLog(#"%#",dict[#"id"]);
}
This will only print id when name is equal to Timeline Photos.
Actually, you are not working with an array, but with a dictionary.
Hope this helps.
Related
I am trying to parse a JSON response into an NSArray for a specific item (geometry/location/lat). I easily manage to get the name into an array with
for (NSDictionary *object in results)
{
NSString *objectName = object[#"name"];
[MyArray addObject:objectName];
}
but I don't know how to dig down to the "lat" level in order to extract this...
JSON DATA full results: (
{
geometry = {
location = {
lat = “15.122494";
lng = “45.518496";
};
};
icon = "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business.png";
id = 1767ee03046d7ac7273be472310cfb6d7b2e6;
name = “Cafe Syracuse”;
photos = (
{
height = 768;
"html_attributions" = (
"From a Google User"
);
"photo_reference" = "CnRoAAAAlVZmfP0Dn3HIwcaEozcjYHqPMC_VlWcvz2sH0yYNjv9DS1GIccAvAp-LNaWxAWKvnEifhPU-1b8ETx7sXtOR7UKSs7tOBpai4FPM1y6M-lcL2qJ4M0dizbHStidxuGCF_QnE548qsE1tP2ZTdhjY_BIQKxSTS_-rPxGlOZmAG7oUUBSiV276H4CemarEXRozEtVr5Vs";
width = 1024;
}
);
"place_id" = ChIJB6K6CExRr8f4AvaA09U;
rating = "4.5";
reference = "CnRjAAAA5Yh4QrEnn7xH2URR7-gwwrhbUz2qmlwbCRW4-JkMfINdldXIYhQR8p2kTdiZiYsdX67nwINp963XIxysFPWOAVZ-okFCu0VH9NL66EWiPSVBFGSgYKXCd7LuhOFMgeU1yLuegyCMQ7RX6mjkhIQiVVok262SeOJGsChxoUXx6DKhp7t_uM51w2y9_bJAlscAA";
scope = GOOGLE;
types = (
cafe,
establishment
);
vicinity = “White glacier";
},
{
geometry = //Other item
Many thanks
This would help you to get lat and long:
NSString*lat= [[[object valueForKey:#"geometry"] valueForKey:#"location"] valueForKey:#"lat"];
NSString *lng= [[[object valueForKey:#"geometry"] valueForKey:#"location"] valueForKey:#"lng"];
<__NSArrayM 0x82701fe0>(
{
Distance = "2.08";
address = Manjalpur;
dob = "09-04-1986 ";
email = "kan#t.com";
facebookid = "";
fname = kanan;
gender = Female;
imageurl = "https://foursquare.com/img/categories_v2/food/indian_";
lastlogin = "/Date(1378288646803+0000)/";
latitude = "22.27052139756";
lname = kanan;
longitude = "73.196614980698";
name = "Green Chillies";
photopath1 = "";
time = "/Date(1378288744627+0000)/";
userid = 202;
},
{
Distance = "2.08";
address = Manjalpur;
dob = "09-04-1986 ";
email = "kan#t.com";
facebookid = "";
fname = kanan;
gender = Female;
imageurl = "https://ss1.4sqi.net/img/categories_v2/food/indian_";
lastlogin = "/Date(1378288646803+0000)/";
latitude = "22.27052139756";
lname = kanan;
longitude = "73.196614980698";
name = "Green Chillies";
photopath1 = "";
time = "/Date(1378288744627+0000)/";
userid = 202;
},
{
Distance = "2.12";
address = Manjalpur;
dob = "03-11-1983";
email = "r#tax.com";
facebookid = 100001835956323;
fname = Rohan;
gender = Female;
imageurl = "https://foursquare.com/img/categories_v2/building/apartment_";
lastlogin = "/Date(1385115357020+0000)/";
latitude = "22.270002988846";
lname = Panchal;
longitude = "73.197391863176";
name = "Tulsidham circle";
photopath1 = "http://taxsmart.in/FTP_Data/S55_2.jpg";
time = "/Date(1381412082083+0000)/";
userid = 55;
},
{
Distance = "2.12";
address = Manjalpur;
dob = "03-11-1983";
email = "r#tax.com";
facebookid = 100001835956323;
fname = Rohan;
gender = Female;
imageurl = "https://ss1.4sqi.net/img/categories_v2/building/apartment_";
lastlogin = "/Date(1385115357020+0000)/";
latitude = "22.270002988846";
lname = Panchal;
longitude = "73.197391863176";
name = "Tulsidham circle";
photopath1 = "http://taxsmart.in/FTP_Data/S55_2.jpg";
time = "/Date(1381412082083+0000)/";
userid = 55;
}
)
my NSDictionary *finalResult print this result
Actually there are only two records but from web service I am getting
this type of result they cannot distinct because of unique imageurl.
so how can i remove duplicate data set.The same user data are only differ from each other with key imageurl.
I just want only single record of user does not matter which one(any one). So finally I will get only two record
//You can filter you response like this:
//tempArray is data array which content webservice response
NSMutableArray *mainArray = [[NSMutableArray alloc]init];
for (int i = 0; i< [temprray count]; i ++) {
if ([mainArray count]==0) {
[mainArray addObject:[temprray objectAtIndex:0]];
}
else {
NSDictionary *tempDict = [temprray objectAtIndex:i];
BOOL isRecordFound = NO;
for (int j = 0; j < [mainArray count]; j++) {
NSDictionary *tempinnerDict = [mainArray objectAtIndex:j];
if ([[tempinnerDict valueForKey:#"userid"] integerValue] == [[tempDict valueForKey:#"userid"] integerValue]) {
isRecordFound = YES;
break;
}
}
if (!isRecordFound) {
[mainArray addObject:tempDict];
}
}
}
It may be a webservice error. Best way is to contact web team or you can remove the duplicates by using below way
You can check the duplicate dictionary with the below method
- (BOOL)isEqualToDictionary:(NSDictionary *)otherDictionary
Inside a for loop you can check the duplicates and if there anyone, you can remove it from an NSMutableArray using
- (void)removeObjectAtIndex:(NSUInteger)index
I am getting json format correctly but the thing is i want to retrieve album images one by one and display it in grid view ...please anybody suggest some code or idea...
Pl suggest me how to get album id for each photos in albums
Results: {
data = (
{
"can_upload" = 1;
count = 2;
"cover_photo" = 1404379296458611;
"created_time" = "2013-10-04T11:35:21+0000";
from = {
id = 100006596624401;
name = "sample";
};
id = 1404366983126509;
link = "https://www.facebook.com/album.php?fbid=1404366983126509&id=100006596624401&aid=1073741827";
name = "Photos";
privacy = custom;
type = app;
"updated_time" = "2013-10-09T07:41:48+0000";
},
{
"can_upload" = 0;
"created_time" = "2013-10-08T10:55:52+0000";
from = {
id = 100006596624401;
name = "sample";
};
id = 1406014439628430;
link = "https://www.facebook.com/album.php?fbid=1406014439628430&id=100006596624401&aid=1073741829";
name = "he Photos";
privacy = custom;
type = app;
"updated_time" = "2013-10-08T11:33:49+0000";
},
{
"can_upload" = 0;
count = 1;
"cover_photo" = 1405547679675106;
"created_time" = "2013-10-07T06:21:36+0000";
from = {
id = 100006596624401;
name = "sample";
};
id = 1405547666341774;
link = "https://www.facebook.com/album.php?fbid=1405547666341774&id=100006596624401&aid=1073741828";
name = test;
privacy = everyone;
type = normal;
"updated_time" = "2013-10-07T06:21:47+0000";
},
{
"can_upload" = 0;
"created_time" = "2013-09-25T05:30:31+0000";
from = {
id = 100006596624401;
name = "sample";
};
id = 1399900213573186;
link = "https://www.facebook.com/album.php?fbid=1399900213573186&id=100006596624401&aid=1073741825";
name = "iOS Photos";
privacy = everyone;
type = app;
"updated_time" = "2013-09-25T06:26:13+0000";
}
);
paging = {
cursors = {
after = "MTM5OTkwMDIxMzU3MzE4Ng==";
before = "MTQwNDM2Njk4MzEyNjUwOQ==";
};
};
Try this
FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:#"me/albums" withGetVars:nil];
NSDictionary *albums = (NSDictionary *)[fb_graph_response.htmlResponse JSONValue];
NSMutableArray * albumids = [[NSMutableArray alloc] init];
albumids = [albums objectForKey:#"data"];
for(int i =0; i< [albumids count]; i++)
{
NSDictionary *dictuser = (NSDictionary *)[albumids objectAtIndex:i];
[album addObject:[dictuser objectForKey:#"id"]];
[albumname addObject:[dictuser objectForKey:#"name"]];
}
Swift 4.0 Version
let request = FBSDKGraphRequest.init(graphPath: "/me/albums", parameters: ["fields": "photo_count,name,id" ], httpMethod: "GET")
request?.start(completionHandler: { (connection, result, error) in
})
In case you want to get picture of Album then use this
"fields": "photo_count,name,id, picture"
Facebook also have a Graph Api Explorer which is very helpful
I have an array (NSArray) with the following content:
dates {
dateOne = {
"date_one" = "2011-11-30";
name = "test1";
dateOne=true
};
dateTwo = {
"date_two" = "2011-11-30";
name = "test2";
dateTwo=false
};
dateThree = {
"date_Three" = "2011-11-30";
dateTwo=true;
name = "test3";
};
the content above is being generating with the following line of code:
NSArray *dates = [myXmlParsed valueForKeyPath:#"myXml.dates"];
using NSLog:
NSLog(#"%#, '%#'", NSStringFromClass([dates class]), dates);
I get the following output:
__NSDictionaryM, '{
dateOne = {
"date_one" = "2011-11-30";
name = "test1";
dateOne=true
};
dateTwo = {
"date_two" = "2011-11-30";
name = "test2";
dateTwo=false
name = "test3";
};
dateThree = {
"date_Three" = "2011-11-30";
name = "test1";
dateTwo=true;
name = "test3";
};
}'
but I'm having problems getting the values of dictionaries inside of the array. My question is how can get the data of dateThree and how can I access to individual node of information for example date_Three ?
I'll really appreciate your help guys
I figure it out. I was using nsarray when I should have done nsmutabledictionary.
NSMutableDictionary *dates=[[NSMutableDictionary alloc] initWithDictionary: [resultDict valueForKeyPath:#"myXml.dates"]];
Now I can query any of the values:
NSLog(#"value %#", [[dates valueForKey:#"dateOne"] valueForKey:#"date_one"]);
i want to retrive KpiName key(KpiData is array inside kpiName is dictionary key) and my data structure mentioned below
--Array of dictionaries inside array of dictinary
ex..listOfProjectsArray--(
{
alertSeverity = 1;
customerName = TPMG;
endDate = "05-05-2013";
isProjectHide = 1;
kpiData = (
{
KpiName = "Change Request ";
kpiActual = 14;
kpiPlanned = "";
kpiUnit = "";
},
{
KpiName = "Aged Debit";
kpiActual = 24000;
kpiPlanned = "";
kpiUnit = EUR;
},
);
lastInvoiceDate = "05-04-2013";
nextBillingDate = "05-04-2013";
nextMilestoneDate = "10-04-2013";
nextReviewDate = "08-04-2013";
plannedCompletionDate = "04-05-2013";
projectID = 3000;
projectName = "Rain Harvesting";
projectSortType = "";
projectStatus = 1;
startDate = "01-01-2013";
},
i tried this one but its returning null
NSString *kpiName = [[[[listOfProjectsArray objectAtIndex:indexPath.row] valueForKey:#"kpiData"] objectAtIndex:0]valueForKey:#"kpiName"];
NSLog(#"kpiname:%#", kpiName);
Try this
NSString *kpiName =[[[[listOfProjectsArray objectAtIndex:indexPath.row] objectForKey:#"kpiData"]objectAtIndex:0]objectForKey:#"KpiName"];
I was mentioned wrong dictionary key
NSString *kpiName = [[[[listOfProjectsArray objectAtIndex:indexPath.row] valueForKey:#"kpiData"] objectAtIndex:0]valueForKey:#"kpiName"];
NSLog(#"kpiname:%#", kpiName);
correct one is KpiName key instead of kpiName.