I am using JSONModel for a basic app that returns a JSON object.
Here is a sample of the data I am returning: https://gist.github.com/ryancoughlin/8043604 - Focusing on the tide
object.
I am trying to work in JSONModel JSONKeyMapper
- docs here (scroll down towards the middle) - https://github.com/icanzilb/JSONModel/blob/master/README.md#magical-data-modelling-framework-for-json
I am trying to find out how to implement it. I understand that it takes a key path similar too:
EDIT: From my breakpoint: http://dl.dropbox.com/u/19301636/Screenshots/rzqv.png
This is what json
returns: http://dl.dropbox.com/u/19301636/Screenshots/y5mt.png
TIDEMAPPER.M
#import "TideMapper.h"
@implementation TideMapper
+(JSONKeyMapper*)keyMapper
{
return [[JSONKeyMapper alloc] initWithDictionary:@{
@"tide.tideInfo": @"tideSite",
@"tide.tideSummaryStats": @"maxheight",
}];
}
@end
TIDEMAPPER.M
#import "TideMapper.h"
@implementation TideMapper
+(JSONKeyMapper*)keyMapper
{
return [[JSONKeyMapper alloc] initWithDictionary:@{
@"tideSummaryStats.maxheight": @"maxheight",
@"tideSummaryStats.minheight": @"minheight",
@"tideInfo.lat": @"lat",
@"tideInfo.lon": @"lon"
}];
}
@end
VIEW
@implementation TideDetailViewController
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:YES];
NSString *locationQueryURL = @"http://api.wunderground.com/api/xxxx/tide/geolookup/q/43.5263,-70.4975.json";
[JSONHTTPClient getJSONFromURLWithString: locationQueryURL
completion:^(NSDictionary *json, JSONModelError *err) {
// NSArray* results = [json valueForKeyPath:@"tide.tideInfo"];
_tide = [TideMapper arrayOfDictionariesFromModels:json];
NSLog(@"loans: %@", _tide);
}];
}
I think I need to change tide
to NSDictionary
- I dont think it returns an array. Its only a single result for a location
I am stuck when it comes to calling this method. Does anyone have any experience using this JSONModel KeyMapper?
Thanks