Note that there are some explanatory texts on larger screens.

plurals
  1. POJSONModel - Using & Implementing KeyMapper
    text
    copied!<p>I am using JSONModel for a basic app that returns a JSON object.</p> <p>Here is a sample of the data I am returning: <a href="https://gist.github.com/ryancoughlin/8043604" rel="nofollow">https://gist.github.com/ryancoughlin/8043604</a> - Focusing on the <code>tide</code> object.</p> <p>I am trying to work in JSONModel <code>JSONKeyMapper</code> - docs here (scroll down towards the middle) - <a href="https://github.com/icanzilb/JSONModel/blob/master/README.md#magical-data-modelling-framework-for-json" rel="nofollow">https://github.com/icanzilb/JSONModel/blob/master/README.md#magical-data-modelling-framework-for-json</a></p> <p>I am trying to find out how to implement it. I understand that it takes a key path similar too:</p> <hr> <p>EDIT: From my breakpoint: <a href="http://dl.dropbox.com/u/19301636/Screenshots/rzqv.png" rel="nofollow">http://dl.dropbox.com/u/19301636/Screenshots/rzqv.png</a></p> <p>This is what <code>json</code> returns: <a href="http://dl.dropbox.com/u/19301636/Screenshots/y5mt.png" rel="nofollow">http://dl.dropbox.com/u/19301636/Screenshots/y5mt.png</a></p> <hr> <p><strong>TIDEMAPPER.M</strong></p> <pre><code>#import "TideMapper.h" @implementation TideMapper +(JSONKeyMapper*)keyMapper { return [[JSONKeyMapper alloc] initWithDictionary:@{ @"tide.tideInfo": @"tideSite", @"tide.tideSummaryStats": @"maxheight", }]; } @end </code></pre> <p><strong>TIDEMAPPER.M</strong></p> <pre><code>#import "TideMapper.h" @implementation TideMapper +(JSONKeyMapper*)keyMapper { return [[JSONKeyMapper alloc] initWithDictionary:@{ @"tideSummaryStats.maxheight": @"maxheight", @"tideSummaryStats.minheight": @"minheight", @"tideInfo.lat": @"lat", @"tideInfo.lon": @"lon" }]; } @end </code></pre> <p><strong>VIEW</strong></p> <pre><code>@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); }]; } </code></pre> <p>I think I need to change <code>tide</code> to <code>NSDictionary</code> - I dont think it returns an array. Its only a single result for a location</p> <p>I am stuck when it comes to calling this method. Does anyone have any experience using this JSONModel KeyMapper? </p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload