0

i have a problem in reading JSON by JSONModel library https://github.com/icanzilb/JSONModel

and use the KivaDemo at the JSonModel app,the json :

"loans": [
{
  "id": 547665,
  "name": "Veronica",
  "description": {
    "languages": [
      "en"
    ]
  },
  "status": "fundraising",
  "funded_amount": 0,

i want to get the "en" ,

@interface KivaFeed : JSONModel

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

@property (strong, nonatomic) Paging *paging;

@end


@protocol LoanModel @end    

@interface LoanModel : JSONModel

@property (strong, nonatomic) NSString* name;
@property (strong, nonatomic) NSString* status;
@property (strong, nonatomic) NSString* use;


@property (strong, nonatomic) NSString* id;
@property (strong, nonatomic) NSString* funded_amount;




@property (strong, nonatomic) LocationModel* location;

@property (strong, nonatomic) Image* image;

@property (strong, nonatomic) Description* description;

@end

@interface Description : JSONModel

@property (strong, nonatomic) NSArray<Languages, ConvertOnDemand>* languages;

@end


@protocol Languages @end    

@interface Languages : JSONModel

@end

kiva = [[KivaFeed alloc] initFromURLWithString:@"http://api.kivaws.org/v1/loans/search.json?status=fundraising"
        completion:^(JSONModel *model, JSONModelError *e) {

            [table reloadData];

            NSLog(@"kiva.paging.page:%@",kiva.paging.page);

            if (e) {
                [[NSAlert alertWithError:e] beginSheetModalForWindow:self.view.window modalDelegate:nil didEndSelector:nil contextInfo:nil];
            }

            [self setLoaderVisible:NO];
        }];



   LoanModel* loan = kiva.loans[row];
            NSString* message = [NSString stringWithFormat:@"%@ from %@(%@) needs a loan %@",
                                 loan.name, loan.location.country, loan.location.countryCode, loan.use
                                 ];

            NSLog(@"loan:%@",loan.id);
            NSLog(@"loan:%@",loan.funded_amount);
            NSLog(@"loan.image.id:%@",loan.image.id);



            NSLog(@"loan.description.languages:%@",loan.description.languages[0]);

last it give me 2013-04-15 13:16:09.163 JSONModelDemo_OSX[2308:303] loan.description.languages:(null). how to get the en,what mistake at my code?

4

1 回答 1

1

修改为:

  @interface Description : JSONModel
  @property (strong, nonatomic) NSArray* languages;
  @end

一切都好

于 2013-04-15T05:57:40.297 回答