Json传递在iphone
我从我的WebService JSONstring传递给我的代码使用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]; }
使用这个我从WebServies,数据像
{ 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 = ""; },
等500左右像块一块在这里。 我很容易getField像FNAME,LNAME,sorting外部字段我轻松访问,但问题,以获得“DateOfBirth”字段我尝试所有的东西,但没有工作,如果有人知道它然后给我的build议
DateOfBirth字段只是一个NSDictionary。 所以你可以像这样检索它:
... NSDictionary *dof = [[rnameary objectAtIndex:i] objectForKey:@"DateOfBirth"]; NSString *date = [dof objectForKey:@"date"]; ...
当你运行一个循环访问这个NSDictionary中的不同键值时,再次分配objectForKey: DateOfBirth
到另一个NSDictionary。 喜欢:
NSDictionary *dict = [self getData:response]; NSDictionary *dictDateofBirth = [dict objectForKey:@"DateOfBirth"];
现在你可以使用这个作为一个单独的NSDictionary和访问date如果诞生如:
NSString *dob = [dictDateofBirth objectForKey:@"date"];