0

trying to parse JSON from http://sec.kimonolabs.com/companies with the JSONModel framework but the problem is that values logged come out as null.

I am trying to output the name and cik of some companies with the SEC API on a table view but currently there is no output because the values are null.

The .m files for the below code are just default with no custom code.

Any help appreciated!

LoanModel.h

#import "JSONModel.h"
//#import "LocationModel.h"

@protocol LoanModel @end
@interface LoanModel : JSONModel

@property (strong, nonatomic) NSString* cik;
@property (strong, nonatomic) NSString* display_name;
@property (strong, nonatomic) NSString* name;
//@property (strong, nonatomic) LocationModel* location;

@end

KivaFeed.h

#import "JSONModel.h"
#import "LoanModel.h"

@interface KivaFeed : JSONModel

@property (strong, nonatomic) NSArray<LoanModel>* company;

@end

MasterViewController.h

#import "MasterViewController.h"
#import "JSONModelLib.h"
#import "KivaFeed.h"

@interface MasterViewController () {
    KivaFeed* _feed;

}
@end

@implementation MasterViewController

-(void)viewDidAppear:(BOOL)animated
{
    //show loader view
    //[HUD showUIBlockingIndicatorWithText:@"Fetching JSON"];

    //fetch the feed
    _feed = [[KivaFeed alloc] initFromURLWithString:@"http://sec.kimonolabs.com/companies" completion:^(JSONModel *model, JSONModelError *err) {

                                             //hide the loader view
                                             //[HUD hideUIBlockingIndicator];

                                             //json fetched
                                              NSLog(@"loans: %@", _feed.company);
                                             NSLog(@"loans: %@", _feed.company);

                                             //reload the table view
                                             [self.tableView reloadData];



                                         }];
}

#pragma mark - table methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _feed.company.count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LoanModel* loan = _feed.company[indexPath.row];

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    cell.textLabel.text = [NSString stringWithFormat:@"%@ and %@", loan.name, loan.cik];
    return cell;
}

@end
youngkg7
  • 1
  • 2
  • initFromURLWithString can you provide the defination for this method initFromURLWithString is not present in JSONModel – Rajan Maheshwari Jul 18 '15 at 08:09
  • I think the problem is that there is no root NAME for the array – Rajan Maheshwari Jul 18 '15 at 08:39
  • You are using the custom asynchronous init method of JSONModel “initFromURLWithString:completion:“. The initialiser method fetches the JSON at the provided URL, and when done, updates the model object and invokes the provided block. – youngkg7 Jul 19 '15 at 21:37
  • Thats what i got from the tutorial i was working on but i just found a another question on stack overflow similar to mine: http://stackoverflow.com/questions/18890762/jsonmodel-returns-nil – youngkg7 Jul 19 '15 at 21:39
  • I tried using the above solution and it works for me. – youngkg7 Aug 01 '15 at 04:16

0 Answers0