JSONModel NSString问题

时间:2016-02-18 12:06:07

标签: ios objective-c jsonobject

在我的应用程序中我使用Yahoo Api并获得响应我现在使用JSONModel创建一个json JSONModel类。

Past_Match.h 文件赞

#import <JSONModel/JSONModel.h>
@protocol squadModel @end
@interface squadModel : JSONModel
@property (assign, nonatomic) int i;
@property (strong, nonatomic) NSString *full;
@end


@interface logoModel : JSONModel
@property (strong, nonatomic) NSString *std;
@end



@protocol teamsModel @end
@interface teamsModel : JSONModel
@property (assign, nonatomic) int i;
@property (strong, nonatomic) NSString *fn;
@property (strong, nonatomic) NSString *sn;
@property (strong, nonatomic) logoModel *logo;
@property (strong, nonatomic) NSArray<squadModel> *squad;
@end

@interface aModel : JSONModel
@property (assign, nonatomic) int i;
@property (assign, nonatomic) int r;
@property (assign, nonatomic) int o;
@property (assign, nonatomic) int w;
@property (assign, nonatomic) int cr;
@end


@interface sModel : JSONModel
@property (strong, nonatomic) aModel *a;
@end

@protocol tModel @end
@interface tModel : JSONModel
@property (assign, nonatomic) int i;
@property (assign, nonatomic) int a;
//@property (strong, nonatomic) NSString *c;
//@property (strong, nonatomic) NSString *dt;
@property (assign, nonatomic) int fd;
@property (assign, nonatomic) int bd;
//@property (strong, nonatomic) NSString *cb;
@property (assign, nonatomic) int b;
@property (assign, nonatomic) int r;
@property (assign, nonatomic) int sr;
@property (assign, nonatomic) int six;
@property (assign, nonatomic) int four;

@end


@interface anewModel : JSONModel
@property (strong, nonatomic) NSArray<tModel> *t;
@end


@interface dModel : JSONModel
@property (strong, nonatomic) anewModel *a;
@end


@protocol past_ingsModel @end
@interface past_ingsModel : JSONModel
@property (strong, nonatomic) sModel *s;
@property (strong, nonatomic) dModel *d;
@end


@interface ScorecardModel : JSONModel
@property (strong, nonatomic) NSString *mid;
@property (strong, nonatomic) NSArray<teamsModel> *teams;
@property (strong, nonatomic) NSArray<past_ingsModel> *past_ings;

@end

@interface resultsModel : JSONModel
@property (strong, nonatomic) ScorecardModel *Scorecard;

@end


@interface queryModel : JSONModel
@property (strong, nonatomic) resultsModel *results;

@end


@interface Past_Match : JSONModel
@property (strong, nonatomic) queryModel *query;
@end

Past_Match.m 文件赞

#import "Past_Match.h"


@implementation squadModel
@end

@implementation logoModel
@end

@implementation teamsModel
@end

@implementation aModel
@end

@implementation sModel
@end

@implementation tModel
@end

@implementation anewModel
@end

@implementation dModel
@end

@implementation past_ingsModel
@end

@implementation ScorecardModel
@end

@implementation resultsModel
@end

@implementation queryModel
@end

@implementation Past_Match
@end
tModel中的

如果我删除//并尝试获取NSString cdtcd个对象,则会出现问题我的Past_Match对象变为空。所有3 NSString都有同样的问题,我无法获得该值。所有其他价值都在增加。我错过了什么?在此先感谢..

1 个答案:

答案 0 :(得分:1)

由于响应对象中的可选值可能会发生此错误,请尝试此操作....可能有效

@property (strong, nonatomic)NSString<Optional> *c;
@property (strong, nonatomic) NSString<Optional> *dt;
@property (strong, nonatomic) NSString<Optional> *cb;

提示:请将所有属性设为可选