Reputation: 120
i pass Json String from my WebService to My code Using NSDictionary
-(void)getData :(NSData*)respo{
NSError *error;
NSMutableDictionary *jons =[NSJSONSerialization JSONObjectWithData:respo options:kNilOptions error:&error];
NSMutableArray *rnameary = [jons objectForKey:@"posts"];
NSMutableArray *tempary =[[NSMutableArray alloc]init];
for (int i=0;i < [rnameary count];i++) {
CfResultFatch *rs = [[CfResultFatch alloc] initWithName:[[rnameary objectAtIndex:i]objectForKey:@"BrandName"]
cipd:[[rnameary objectAtIndex:i] objectForKey:@"Dose"]];
[tempary addObject:rs];
}
result = [[NSMutableArray alloc] initWithArray:tempary];
[temptab reloadData];
}
using this i get Data from WebServies, Data like
{
ActiveCrNo = "";
BPL = 0;
BloodGroupIDF = 1;
CRNumber = 0000187;
CashlessDetail = fgfghgfh;
CastIDF = 19;
ClassIDF = 7;
CloseCrNo = 0;
CompanyNo = "";
DateOfBirth = {
date = "1987-08-20 00:00:00";
timezone = "Europe/Berlin";
"timezone_type" = 3;
};
Disability = 0;
EntryDate = {
date = "2011-08-20 16:30:00";
timezone = "Europe/Berlin";
"timezone_type" = 3;
};
ExpiredDate = "<null>";
ExtraField1 = 0;
ExtraField2 = "<null>";
FName = "Mrs.Shatayu";
Gender = 0;
HospitalIDF = 4;
IncomeGroupIDF = "<null>";
IsExpired = 0;
IsNewPatient = 0;
LName = Sharma;
MName = Maheshbhai;
MaritalStatus = 0;
PAN = "";
PatientIDP = 202;
QualificationIDF = "<null>";
ReligionIDF = "<null>";
Remarks = "";
SkillSetIDF = "<null>";
UIDNumber = "";
},
And so on around 500 block like one is here. i easily getField Like FNAME, LNAME, in sort outer field i Access easily but problem to get "DateOfBirth" field i was try all the things but nothing work if some one know it then give me suggestion
Upvotes: 0
Views: 168
Reputation: 2122
When you run a loop for accessing value for different keys in this NSDictionary, again assign the objectForKey: DateOfBirth
to another NSDictionary. Like:
NSDictionary *dict = [self getData:response];
NSDictionary *dictDateofBirth = [dict objectForKey:@"DateOfBirth"];
Now you can use this as an individual NSDictionary and access the date if birth like:
NSString *dob = [dictDateofBirth objectForKey:@"date"];
Upvotes: 1
Reputation: 35626
DateOfBirth field is just an NSDictionary. So you could retrieve it like:
...
NSDictionary *dof = [[rnameary objectAtIndex:i] objectForKey:@"DateOfBirth"];
NSString *date = [dof objectForKey:@"date"];
...
Upvotes: 1