how to select image from JSON parsed in Array - iphone

I am using JSON parsing, I put data in array named JSON Array. In console it looks like
JSON Array=(
{
"created_by" = 42;
"created_on" = "2012-02-29 11:23:37";
"file_description" = "";
"file_is_downloadable" = 0;
"file_is_forSale" = 0;
"file_is_product_image" = 1;
"file_meta" = "";
"file_mimetype" = "image/jpeg";
"file_params" = "";
"file_title" = "hand shovel";
"file_type" = product;
"file_url" = "images/stories/virtuemart/product/cca3cd5db813ee6badf6a3598832f2fc.jpg";
"file_url_thumb" = "images/stories/virtuemart/product/resized/cca3cd5db813ee6badf6a3598832f2fc_90x90.jpg";
"locked_by" = 0;
"locked_on" = "0000-00-00 00:00:00";
"modified_by" = 42;
"modified_on" = "2012-02-29 11:23:37";
ordering = 0;
"product_name" = "Hand Shovel";
published = 0;
shared = 0;
"virtuemart_category_id" = 1;
"virtuemart_media_id" = 13;
"virtuemart_product_id" = 1;
"virtuemart_vendor_id" = 1;
},
{
"created_by" = 42;
"created_on" = "2012-02-29 11:35:09";
"file_description" = "";
"file_is_downloadable" = 0;
"file_is_forSale" = 0;
"file_is_product_image" = 1;
"file_meta" = "";
"file_mimetype" = "image/jpeg";
"file_params" = "";
"file_title" = "our ladder";
"file_type" = product;
"file_url" = "images/stories/virtuemart/product/8cb8d644ef299639b7eab25829d13dbc.jpg";
"file_url_thumb" = "images/stories/virtuemart/product/resized/8cb8d644ef299639b7eab25829d13dbc_90x90.jpg";
"locked_by" = 0;
"locked_on" = "0000-00-00 00:00:00";
"modified_by" = 42;
"modified_on" = "2012-02-29 11:35:09";
ordering = 0;
"product_name" = Ladder;
published = 0;
shared = 0;
"virtuemart_category_id" = 3;
"virtuemart_media_id" = 8;
"virtuemart_product_id" = 2;
"virtuemart_vendor_id" = 1;
},
Now from this i need to select "file_url_thumb" which is actually image in seperate array.
please let me know how can i do this?

//Your array has two dictionary ..
for(NSMutableDictionary *dict in JSON_Array){
NSString *urlString = [dict objectForKey:#"file_url_thumb"];
if(urlString){
NSURL *url = [NSURL urlWithString:urlString];
NSData* imageData = [[NSData alloc] initWithContentsOfURL:url]];
UIImage* image = [[UIImage alloc] initWithData:imageData];
//show your image on imageview
}
}
Hope this will help you

NSString *str_URL =[ [json objectAtIndex:anIndex] valueForKey:#"file_url_thumb"];

NSString *urlString = [[jsonArray objectAtIndex:0] objectForKey:#"file_url_thumb"];
This will give you value for "file_url_thumb" as a string.

Related

How to get data into NSArray from NSDictionary

i am getting following error while getting data from dictionary
"-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x4fbb80"
here is my code
NSDictionary *dic = [XMLReader dictionaryForXMLString:class.returnData error:nil];
MyGiftsarray = [[dic objectForKey:#"response"] objectForKey:#"gifts"];
for (NSDictionary *element in MyGiftsarray) {
[MyGiftsnamearray addObject:[element objectForKey:#"name"]];
[MyGiftsChkarray addObject:[element objectForKey:#"chk"]];
[MyGiftsIdarray addObject:[element objectForKey:#"id"]];
[MyGiftsApprovedarray addObject:[element objectForKey:#"approved"]];
[MyGiftsisCompletedarray addObject:[element objectForKey:#"completed"]];
}
this is NSDictionary from which i try to get data.
MyGiftsDict->(
{
Appliedpoint = 500;
Requiredpoint = 5000;
approved = N;
chk = 50;
completed = 0;
id = 66;
name = "1-800Flowers.com";
},
{
Appliedpoint = 85;
Requiredpoint = 2500;
approved = N;
chk = 25;
completed = 0;
id = 71;
name = "Bath Body Works";
},
{
Appliedpoint = 5;
Requiredpoint = 2500;
approved = N;
chk = 25;
completed = 0;
id = 75;
name = "Buca di Beppo";
},
{
Appliedpoint = 36;
Requiredpoint = 2500;
approved = N;
chk = 25;
completed = 0;
id = 66;
name = "1-800Flowers.com";
},
{
Appliedpoint = 25;
Requiredpoint = 5000;
approved = N;
chk = 50;
completed = 0;
id = 90;
name = "Jelly Belly";
},
{
Appliedpoint = 120;
Requiredpoint = 500;
approved = N;
chk = 5;
completed = 0;
id = 129;
name = "Amazon.com";
}
)
You are iterating in wrong manner-
Use -
MyGiftsDict = [[dic objectForKey:#"response"] objectForKey:#"gifts"];
And then iterate over dictionary step by step.
You need to use something like -
for(NSString *key in [MyGiftsDict allKeys])
{
[MyGiftsnamearray addObject:[MyGiftsDict objectForKey:key]];
}
Gifts is an NSDictionary in itself. It's not an NSArray! You don't need that for loop. Use simply
[MyGiftsNameArray addObject:[MyGiftsArray objectForKey:#"name"];
et cetera.
I don't think you will need the forcycle.

how to access all the array of dictionary contents

I have implemented the array of dictionary contents accessing methods but it is access only one content, please help on this
Here is my data file
<__NSArrayM 0x8b7a350>(
{
clkDate = "Wednesday, April 11, 2012";
resData = (
{
data = 10;
independentItem = 0;
module = 6;
newDate = "11-4-2012";
newTime = "13:31";
seqCounter = 101;
sequence = 10007;
session = 101;
timeframe = Breakfast;
timestamp = "2012-04-11 08:01:27 +0000";
title = "Glucose reading : Low";
type = L;
},
{
data = {
hours = 0;
minutes = 0;
which = "Walking:(null)";
};
independentItem = 1;
module = 13;
seqCounter = 101;
sequence = 10009;
session = 101;
timestamp = "2012-04-12 08:01:40 +0000";
title = "Low Cause: Increased Exercise";
}
);
seqCounter = 101;
},
{
clkDate = "Thursday, April 12, 2012";
resData = (
{
data = 200;
independentItem = 0;
module = 6;
newDate = "12-4-2012";
newTime = "13:31";
seqCounter = 102;
sequence = 10017;
session = 101;
timeframe = Breakfast;
timestamp = "2012-04-12 08:01:46 +0000";
title = "Glucose reading : High";
type = H;
},
{
data = {
hours = 0;
minutes = 0;
which = "Other Light:Kkkkk";
};
independentItem = 1;
module = 26;
seqCounter = 102;
sequence = 10022;
session = 101;
timestamp = "2012-04-11 18:30:00 +0000";
title = "High Cause: Decreased Exercise";
}
);
seqCounter = 102;
},
{
clkDate = "Thursday, April 12, 2012";
clkIndependentItem = 1;
resData = (
{
data = {
bathing = 1;
driving = 1;
grocery = 1;
meal = 1;
};
independentItem = 1;
module = 31;
seqCounter = 103;
sequence = 10035;
session = 101;
timestamp = "2012-04-12 08:02:32 +0000";
title = "High Cause: Decreased activity";
}
);
seqCounter = 103;
}
)
In above data file i need to access "independentItem = 1" related items
i tried source code is
for (int i = 0; i < [self.gluClkDetailArray count]; i++)
{
NSMutableDictionary *mDict = [self.gluClkDetailArray objectAtIndex:i];
{
NSMutableArray *mResData = [mDict objectForKey:#"resData"];
NSDate *mTimestamp = [[mResData objectAtIndex:0] objectForKey:#"timestamp"];
NSDateFormatter *mFormatter = [[NSDateFormatter alloc] init];
[mFormatter setDateStyle:NSDateFormatterFullStyle];
NSString *mClkDate = [mFormatter stringFromDate:mTimestamp];
[mDict setValue:mClkDate forKey:#"clkDate"];
NSString *mIndItem = [[mResData objectAtIndex:0] objectForKey:#"independentItem"];
if (mIndItem.intValue == 1)
{
[mDict setValue:mIndItem forKey:#"clkIndependentItem"];
[mIndpendentArray addObject:mDict];
}
[gluClkResultArray addObject:mDict];
}
when ever i put the mResData objectAtIndex:0 instead of i, app got crashed. i have saved array of dictionary values based on the sequence counter
Thanks in advance
Change
NSString *mIndItem = [[mResData objectAtIndex:0] objectForKey:#"independentItem"];
to that:
NSString *mIndItem = [[mResData objectAtIndex:1] objectForKey:#"independentItem"];
The independentItem is in the dictionary that in at index 1, not 0.
Hope it helps

convert dictionary to array after removing key values

i need to remove first three keys values from each index of array. What i did is
for (int i=0; i<[normalscoringarray count]; i++)
{
NSDictionary *dictionary = [normalscoringarray objectAtIndex:i];
NSMutableDictionary *mutableDictionary = [dictionary mutableCopy];
[mutableDictionary removeObjectForKey:#"cn"];
[mutableDictionary removeObjectForKey:#"gdate"];
[mutableDictionary removeObjectForKey:#"gid"];
NSLog(#"mutableDictionary.....%#",mutableDictionary);
NSMutableArray *remainingArray = [[NSMutableArray alloc]init];
for (id item in mutableDictionary) {
[remainingArray setArray:[mutableDictionary objectForKey:item]];
}
}
and it does not give remainingArray in that order i want, more over it removes all keys.
normalscoringarray....(
{
cn = "Ranjit Garh";
gdate = "2012-03-25";
gid = 1;
id = 1;
p1nets = "3,3,4,4,2,2,2,4,3,3,4,2,5,3,5,4,3,4||27||33||60";
p1nh = "BP||14||1";
p1score = "4,4,5,5,3,3,3,5,4,4,5,3,5,3,6,4,4,5||36||39||75||61";
p1spoints = "3,3,3,2,3,4,3,3,3,3,2,4,1,2,2,1,3,3||27||21||48";
p2nets = "4,3,4,4,3,4,2,5,4,4,3,3,4,3,6,3,4,4||33||34||67";
p2nh = "DG||18||2";
p2score = "5,4,5,5,4,5,3,6,5,5,4,4,5,4,7,4,5,5||42||43||85||67";
p2spoints = "2,3,3,2,2,2,3,2,2,2,3,3,2,2,1,2,2,3||21||20||41";
p3nets = "4,3,6,4,2,3,2,4,5,4,3,5,6,3,4,3,5,6||33||39||72";
p3nh = "NM||24||3";
p3score = "6,5,7,6,4,5,3,6,6,5,5,6,7,4,5,4,6,7||48||49||97||73";
p3spoints = "2,3,1,2,3,3,3,3,1,2,3,1,0,2,3,2,1,1||21||15||36";
p4nets = "3,4,5,4,2,3,3,5,3,4,3,5,4,3,5,3,4,6||32||37||69";
p4nh = "KS||20||4";
p4score = "5,5,6,5,3,5,4,6,4,5,5,6,5,4,6,4,5,7||43||47||90||70";
p4spoints = "3,2,2,2,3,3,2,2,3,2,3,1,2,2,2,2,2,1||22||17||39";
},
{
cn = "Eden Garden";
gdate = "2012-03-26";
gid = 2;
id = 2;
p1nets = "3,2,5,3,1,2,2,4,4,3,4,3,5,2,5,3,3,5||26||33||59";
p1nh = "NM||24||3";
p1score = "5,4,6,5,3,4,3,6,5,4,5,4,6,3,6,4,4,6||41||42||83||59";
p1spoints = "3,4,2,3,4,4,3,3,2,3,2,3,1,3,2,2,3,2||28||21||49";
p2nets = "2,4,5,3,2,4,3,4,4,4,3,3,5,2,5,3,4,4||31||33||64";
p2nh = "KS||20||4";
p2score = "4,5,6,4,3,6,4,5,5,5,4,4,6,3,6,4,5,5||42||42||84||64";
p2spoints = "4,2,2,3,3,2,2,3,2,2,3,3,1,3,2,2,2,3||23||21||44";
p3nets = "3,4,5,5,3,5,4,5,5,5,4,5,5,4,5,3,5,6||39||42||81";
p3nh = "AK||18||5";
p3score = "4,5,6,6,4,6,5,6,6,6,5,6,6,5,6,4,6,7||48||51||99||81";
p3spoints = "3,2,2,1,2,1,1,2,1,1,2,1,1,1,2,2,1,1||15||12||27";
p4nets = "2,4,5,4,3,3,3,5,5,4,3,5,4,3,5,4,5,6||34||39||73";
p4nh = "KR||20||6";
p4score = "4,5,6,5,4,5,4,6,6,5,4,6,5,4,6,5,6,7||45||48||93||73";
p4spoints = "4,2,2,2,2,3,2,2,1,2,3,1,2,2,2,1,1,1||20||15||35";
},
)
the way i want
normalscoringarray....(
id = 1,
p1nets = "3,3,4,4,2,2,2,4,3,3,4,2,5,3,5,4,3,4||27||33||60",
p1nh = "BP||14||1",
p1score = "4,4,5,5,3,3,3,5,4,4,5,3,5,3,6,4,4,5||36||39||75||61",
p1spoints = "3,3,3,2,3,4,3,3,3,3,2,4,1,2,2,1,3,3||27||21||48",
p2nets = "4,3,4,4,3,4,2,5,4,4,3,3,4,3,6,3,4,4||33||34||67",
p2nh = "DG||18||2",
p2score = "5,4,5,5,4,5,3,6,5,5,4,4,5,4,7,4,5,5||42||43||85||67",
p2spoints = "2,3,3,2,2,2,3,2,2,2,3,3,2,2,1,2,2,3||21||20||41",
p3nets = "4,3,6,4,2,3,2,4,5,4,3,5,6,3,4,3,5,6||33||39||72",
p3nh = "NM||24||3",
p3score = "6,5,7,6,4,5,3,6,6,5,5,6,7,4,5,4,6,7||48||49||97||73",
p3spoints = "2,3,1,2,3,3,3,3,1,2,3,1,0,2,3,2,1,1||21||15||36",
p4nets = "3,4,5,4,2,3,3,5,3,4,3,5,4,3,5,3,4,6||32||37||69";
p4nh = "KS||20||4";
p4score = "5,5,6,5,3,5,4,6,4,5,5,6,5,4,6,4,5,7||43||47||90||70",
p4spoints = "3,2,2,2,3,3,2,2,3,2,3,1,2,2,2,2,2,1||22||17||39",
)
NSMutableArray *remainingArray = [[NSMutableArray alloc]init];
for (int i=0; i<[normalscoringarray count]; i++)
{
NSMutableDictionary *mutableDictionary = [[NSMutableDictionary alloc] initWithDictionary:[normalscoringarray objectAtIndex:i]]; //each time alloc and init with contents of normalscoringarray
//Remove values for keys
[mutableDictionary removeObjectForKey:#"cn"];
[mutableDictionary removeObjectForKey:#"gdate"];
[mutableDictionary removeObjectForKey:#"gid"];
[remainingArray addObject:mutableDictionary]; //add mutableDictionary to remainingArray
[mutableDictionary release]; //free mutableDictionary
}
//finally print contents of remainingArray
NSLog(#"normalscoringarray:\n%#",[remainingArray description]);
Hope this would be help you!
for (int i=0; i<[normalscoringarray count]; i++)
{
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithDictionary:[normalscoringarray objectAtIndex:i]];
[dictionary removeObjectForKey:#"cn"];
[dictionary removeObjectForKey:#"gdate"];
[dictionary removeObjectForKey:#"gid"];
[normalscoringarray replaceObjectAtIndex:i withObject:dictionary];
}

Multidimensional array issues

I am creating a multidimensional array for sections / rows based on json data from our API. Looking at the logs the adding rows and sections look good but when I nslog the sections it only shows a bunch of the last object. It seems like the rows are not being added to sections.
What am I doing wrong to make the last API object show in the sections x times? x represents the json count. self.appointments is an NSArray *
According to objective-c multi-dimensional array it should work.
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSMutableArray *sections = [[NSMutableArray alloc] init];
NSMutableArray *rows = [[NSMutableArray alloc] init];
NSString *lastDate = nil;
for (NSDictionary *dict in [json objectForKey:#"data"]) {
NSString *date = [dict objectForKey:#"date"];
NSLog(#"Dates: %# - %#", date, lastDate);
if (date != lastDate) {
if (lastDate == nil) {
NSLog(#"Adding Row 1");
[rows addObject:dict];
lastDate = date;
} else {
NSLog(#"Adding Section 1");
NSLog(#"Adding #rows %i",[rows count]);
[sections addObject:rows];
[rows removeAllObjects];
NSLog(#"Adding Row 2 %#",[dict objectForKey:#"start_time"]);
[rows addObject:dict];
lastDate = date;
}
} else {
NSLog(#"Adding Row 3");
[rows addObject:dict];
}
}
if (rows) {
NSLog(#"Adding Section 2");
NSLog(#"Adding #rows %i",[rows count]);
[sections addObject:rows];
}
NSLog(#"Sections: %#", sections);
self.appointments = [sections mutableCopy]; //I have also tried self.appointments = sections
sections = nil;
rows = nil;
Logs show
Sections: (
(
{
abbrev = "";
account = "";
"addOnService_id" = "";
alert = "";
"appt_id" = 1839384;
"appt_id_unique" = 1839384;
"appt_status_description" = "";
"appt_status_type" = "";
"c_id" = 47;
cost = "0.00";
"coupon_id" = "";
"creation_emp_id" = 2288;
"creation_timestamp" = 201111040717;
"customer_id" = 0;
"customer_notes" = "";
"customer_package_id" = "";
date = 20121228;
"employee_id" = 2288;
"employee_notes" = "";
employer = "";
"end_time" = 570;
"first_name" = "";
"history_id" = 1830959;
key = 134;
"last_emp_id" = 2288;
"last_name" = "";
"last_timestamp" = 201111040717;
"lead_description" = "";
"link_id" = 0;
"location_name" = "Telephonic Setup/Training";
"make_id" = "";
"middle_name" = "";
"model_id" = "";
"model_year" = "";
name = "My Name ";
odometer = "";
"other_vehicle" = "";
"package_name" = "";
"payment_type_description" = "";
"payment_type_id" = "";
"pet_id" = "";
"po_number" = "";
reason = "B.O.B";
"rebook_id" = "";
"recur_id" = 20954;
"rep_id" = "";
"room_id" = 0;
"room_name" = "";
service = "";
"service_id" = 0;
"service_time_description" = "";
spots = 1;
"staff_screen_name" = "John Smith";
"staff_type_id" = 0;
"start_time" = 540;
"status_id" = 0;
tip = "";
"type_id" = 8;
vin = "";
}
),
(
{
abbrev = "";
account = "";
"addOnService_id" = "";
alert = "";
"appt_id" = 1839384;
"appt_id_unique" = 1839384;
"appt_status_description" = "";
"appt_status_type" = "";
"c_id" = 47;
cost = "0.00";
"coupon_id" = "";
"creation_emp_id" = 2288;
"creation_timestamp" = 201111040717;
"customer_id" = 0;
"customer_notes" = "";
"customer_package_id" = "";
date = 20121228;
"employee_id" = 2288;
"employee_notes" = "";
employer = "";
"end_time" = 570;
"first_name" = "";
"history_id" = 1830959;
key = 134;
"last_emp_id" = 2288;
"last_name" = "";
"last_timestamp" = 201111040717;
"lead_description" = "";
"link_id" = 0;
"location_name" = "Telephonic Setup/Training";
"make_id" = "";
"middle_name" = "";
"model_id" = "";
"model_year" = "";
name = "My Name ";
odometer = "";
"other_vehicle" = "";
"package_name" = "";
"payment_type_description" = "";
"payment_type_id" = "";
"pet_id" = "";
"po_number" = "";
reason = "B.O.B";
"rebook_id" = "";
"recur_id" = 20954;
"rep_id" = "";
"room_id" = 0;
"room_name" = "";
service = "";
"service_id" = 0;
"service_time_description" = "";
spots = 1;
"staff_screen_name" = "John Smith";
"staff_type_id" = 0;
"start_time" = 540;
"status_id" = 0;
tip = "";
"type_id" = 8;
vin = "";
}
), ... over and over again.
With:
[sections addObject:rows];
[rows removeAllObjects];
[rows addObject:dict];
you keep adding the same rows object not a new one and keep changing the contents so the last contents display each time.
Try:
[sections addObject:[rows mutableCopy]];
[rows removeAllObjects];
[rows addObject:dict];
That way a new row is added each time.
Perhaps better yet:
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSMutableArray *sections = [NSMutableArray array];
NSMutableArray *rows = [NSMutableArray array];
NSString *lastDate = nil;
for (NSDictionary *dict in [json objectForKey:#"data"]) {
NSString *date = [dict objectForKey:#"date"];
if ([date isEqualToString:lastDate] == NO) {
if (lastDate == nil) {
[rows addObject:dict];
lastDate = date;
} else {
[sections addObject:rows];
rows = [NSMutableArray array];
[rows addObject:dict];
lastDate = date;
}
[rows addObject:dict];
}
}
if (rows) {
[sections addObject:rows];
}
self.appointments = sections;
Note that assigning 0 to an object does not release it, release does. But if you use convenience methods to create objects then they are autoreleased and no further action is necessary to release them.
Also note that when comparing strings one needs to use the isEqualToString: method to compare the contents, just using the = or != only compares the address of the strings.

NSDictionary with dictionary as objects, get objects

I have a NSDictionary like this one.
PhotoData = {
1 = {
"jf_photo_geotag" = "arayat philippines";
"jf_photo_id" = 1;
"jf_photo_url" = "http://adomainname/iphone_images/large/jf_largeimage1.png";
"jf_user_id" = 1;
comments = {
1 = {
"jf_photo_comment" = "well i like this one. really. comment from janus";
"jf_photo_comment_id" = 1;
"jf_photo_id" = 1;
"jf_user_id" = 1;
"jf_username" = janus;
};
4 = {
"jf_photo_comment" = asasfa;
"jf_photo_comment_id" = 4;
"jf_photo_id" = 1;
"jf_user_id" = 1;
"jf_username" = janus;
};
};
likes = {
2 = {
"jf_like_id" = 2;
"jf_photo_id" = 1;
"jf_user_id" = 1;
"jf_username" = janus;
};
};
"post_date" = "2012-02-23 16:34:14";
};
2 = {
"jf_photo_geotag" = "magalang philippines";
"jf_photo_id" = 2;
"jf_photo_url" = "http://adomainname/iphone_images/large/jf_largeimage2.png";
"jf_user_id" = 2;
comments = {
2 = {
"jf_photo_comment" = "well this is now a comment from loaclhost! for phot number 2";
"jf_photo_comment_id" = 2;
"jf_photo_id" = 2;
"jf_user_id" = 2;
"jf_username" = fidel;
};
3 = {
"jf_photo_comment" = asdfadf;
"jf_photo_comment_id" = 3;
"jf_photo_id" = 2;
"jf_user_id" = 2;
"jf_username" = fidel;
};
};
likes = {
1 = {
"jf_like_id" = 1;
"jf_photo_id" = 2;
"jf_user_id" = 1;
"jf_username" = janus;
};
};
"post_date" = "2012-02-23 16:34:31";
};
3 = {
"jf_photo_geotag" = "san fdo philippines";
"jf_photo_id" = 3;
"jf_photo_url" = "http://adomainname/iphone_images/large/jf_largeimage1.png";
"jf_user_id" = 3;
comments = (
);
likes = (
);
"post_date" = "2012-02-24 16:34:47";
};
};
success = 1;
}
basically, this NSDictionary contains some string data like jf_photo_url, jf_photo_id etc. and also it has another dictionary as its object like comments = ()
how can I work with this dictionary to change its structure and produce and maybe create a new Dictionary similar to this one:
PhotoData = {
{
"jf_photo_geotag" = "arayat philippines";
"jf_photo_id" = 1;
"jf_photo_url" = "http://adomainname/iphone_images/large/jf_largeimage1.png";
"jf_user_id" = 1;
comments = (
{
"jf_photo_comment" = "well i like this one. really. comment from janus";
"jf_photo_comment_id" = 1;
"jf_photo_id" = 1;
"jf_user_id" = 1;
"jf_username" = janus;
},
{
"jf_photo_comment" = asasfa;
"jf_photo_comment_id" = 4;
"jf_photo_id" = 1;
"jf_user_id" = 1;
"jf_username" = janus;
}
};
likes = (
{
"jf_like_id" = 2;
"jf_photo_id" = 1;
"jf_user_id" = 1;
"jf_username" = janus;
}
,"post_date" = "2012-02-23 16:34:14";
},
{
"jf_photo_geotag" = "magalang philippines";
"jf_photo_id" = 2;
"jf_photo_url" = "http://adomainname/iphone_images/large/jf_largeimage2.png";
"jf_user_id" = 2;
comments =(
{
"jf_photo_comment" = "well this is now a comment from loaclhost! for phot number 2";
"jf_photo_comment_id" = 2;
"jf_photo_id" = 2;
"jf_user_id" = 2;
"jf_username" = fidel;
},
{
"jf_photo_comment" = asdfadf;
"jf_photo_comment_id" = 3;
"jf_photo_id" = 2;
"jf_user_id" = 2;
"jf_username" = fidel;
};
};
likes = (
{
"jf_like_id" = 1;
"jf_photo_id" = 2;
"jf_user_id" = 1;
"jf_username" = janus;
};
},
"post_date" = "2012-02-23 16:34:31";
},
{
"jf_photo_geotag" = "san fdo philippines";
"jf_photo_id" = 3;
"jf_photo_url" = "http://adomainname/iphone_images/large/jf_largeimage1.png";
"jf_user_id" = 3;
comments = (
);
likes = (
);
"post_date" = "2012-02-24 16:34:47";
};
};
success = 1;
}
notice that the first dictionary has index number in each object. I want to remove them.
my first dictionary is loaded from the server, the second one is from a plist
thanks you guys! I hope you understand my question.
It looks like you want your outer dictionary to be an array instead. Assuming you have this data in an NSDictionary already, you could copy it to an array like so:
NSDictionary* photoDict = some_dict; //your outer dict
NSMutableArray* photoArray = [[[NSMutableArray alloc] init] autorelease];
NSEnumerator *enumerator = [photoDict objectEnumerator];
id value;
while((value = [enumerator nextObject])) {
[photoArray addObject:value];
}
//do something with photoArray