tide.tideSummaryStats
returns an array.tide.tideInfo
returns an array.
So you can't do -valueForKeyPath:
all the way.
Also, this is incorrect: [dictionary valueForKeyPath:...];
it should be : [json valueForKeyPath:...];
because json
is the name of the NSDictionary
variable passed (not dictionary
)
Try this (not sure):
-(id)initWithDict:(NSDictionary *)json {
self = [super init];
if(self) {
NSArray *arrOfTideSummaryStats = [json valueForKeyPath:@"tide.tideSummaryStats"];
NSDictionary *dctOfTideSummaryStats = [arrOfTideSummaryStats objectAtIndex:0];
//since self.maxheight and self.minheight are NSString objects and
//the original keys "minheight" & "maxheight" return float values, do:
self.maxheight = [NSString stringWithFormat:@"%f", [dctOfTideSummaryStats valueForKey: @"maxheight"]];
self.minheight = [NSString stringWithFormat:@"%f", [dctOfTideSummaryStats valueForKey: @"minheight"]];
/*============================================================*/
NSArray *arrOfTideInfo = [json valueForKeyPath:@"tide.tideInfo"];
NSDictionary *dctOfTideInfo = [arrOfTideInfo objectAtIndex:0];
self.tideSite = [dctOfTideInfo valueForKey:@"tideSite"];
}
return self;
}
Similar Questions: