ios - JSONModel NSString 问题

标签 ios objective-c json

在我的应用程序中,我使用 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 中,如果我删除 // 并尝试获取 cNSString,我会遇到问题, dt,cd 对象比我的 Past_Match 对象变成 Null。所有 3 个 NSString 都有相同的问题,我无法获得该值。所有其他值(value)正在获得。我错过了什么?提前致谢..

最佳答案

这个错误可能是由于你的响应对象中的可选值而发生的试试这个......它可能有效

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

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

关于ios - JSONModel NSString 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35481044/

相关文章:

c++ - 使用 json 库创建 json 字符串

javascript - 只有元组时如何从 JSON 将数据加载到 D3 图表

iPhone4如何添加/动画UIView以显示在UIButton下?

ios - 忽略随机 subview 的 UIAppearance 代理而不是整个类

ios - Objective C ViewController 意外旋转到 Landscape

iPhone 应用程序因 sqlite3_bind_text() 而崩溃

安卓/Java : Can't find MultipartEntity class despite adding it to build path

ios - CNContactPickerViewController导航栏颜色

iphone - UIImage 的类方法调用问题

ios - Swift:无法将类型 '() -> Bool' 的值转换为预期的参数类型 'PFObject'