Ios JSONModel库/模型集合错误
我使用JSONMODEl()解析WordPressJSON提要(使用JSONAPI) 一切都很顺利,除非我需要“评论” 我的提要是这样的:Ios JSONModel库/模型集合错误,ios,json,wordpress,jsonmodel,Ios,Json,Wordpress,Jsonmodel,我使用JSONMODEl()解析WordPressJSON提要(使用JSONAPI) 一切都很顺利,除非我需要“评论” 我的提要是这样的: comments = ( { content = "<p>My comment</p>\n"; date = "2014-08-29 20:56:29";
comments = (
{
content = "<p>My comment</p>\n";
date = "2014-08-29 20:56:29";
id = 97813;
name = johndoe;
parent = 0;
url = "http://www.google.com";
}
);
#import "JSONModel.h"
#import "commentmodel.h"
@protocol NewsModel @end
@interface NewsModel : JSONModel
@property (strong, nonatomic) NSString* title;
@property (strong, nonatomic) NSString* content;
@property (strong, nonatomic) NSString* thumbnail_images;
@property (strong, nonatomic) NSString* premium;
@property (strong, nonatomic) NSString* id;
@property (strong, nonatomic) CommentModel* comments;
@end
我的模特就是这样
#import "JSONModel.h"
@interface CommentModel : JSONModel
@property (assign, nonatomic) int id;
@property (strong, nonatomic) NSString* name;
@property (assign, nonatomic) NSString* content;
@end
但当我尝试构建我的应用程序时,我的“提要”是空的
如果我评论新闻模型的“评论”部分,我就得到了内容
我想我被困在什么地方了,但是在哪里呢!如果有人有想法:)
非常感谢
注释
是一个数组,而不是一条注释,请注意顶层的(
和)
,它们在NSDictionary
NSLog()
中指定了一个数组。内部是由{
和}
指定的数组元素
但是NewsModel
将comments
定义为单个注释(CommentModel
),而不是数组。或许应该宣布:
在文档中,请参见如何处理产品
您必须声明一个协议
,请参见“模型集合”示例顶部的示例协议
@protocol CommentModel
@end
以上:
@interface CommentModel : JSONModel
@property (strong, nonatomic) NSArray< CommentModel >* comments;
@interface-CommentModel:JSONModel
@属性(强,非原子)NSArray*注释;
注释
是一个数组,而不是单个注释,请注意顶层的(
和)
,它们在NSLog()中指定了一个数组。内部是由{
和}
指定的数组元素
但是NewsModel
将comments
定义为单个注释(CommentModel
),而不是数组。或许应该宣布:
在文档中,请参见如何处理产品
您必须声明一个协议
,请参见“模型集合”示例顶部的示例协议
@protocol CommentModel
@end
以上:
@interface CommentModel : JSONModel
@property (strong, nonatomic) NSArray< CommentModel >* comments;
@interface-CommentModel:JSONModel
@属性(强,非原子)NSArray*注释;
@协议模型
@结束
@接口模型:JSONModel
@属性(赋值,非原子)int-id;
@属性(强,非原子)NSString*名称;
@属性(赋值,非原子)NSString*内容;
@结束
@接口NewsModel:JSONModel
@属性(强,非原子)NSString*标题;
@属性(强,非原子)NSString*内容;
@属性(强,非原子)NSString*缩略图;
@属性(强,非原子)NSString*高级;
@属性(强,非原子)NSString*id//智力?
@属性(强、非原子)NSArray*注释;
@结束
@协议模型
@结束
@接口模型:JSONModel
@属性(赋值,非原子)int-id;
@属性(强,非原子)NSString*名称;
@属性(赋值,非原子)NSString*内容;
@结束
@接口NewsModel:JSONModel
@属性(强,非原子)NSString*标题;
@属性(强,非原子)NSString*内容;
@属性(强,非原子)NSString*缩略图;
@属性(强,非原子)NSString*高级;
@属性(强,非原子)NSString*id//智力?
@属性(强、非原子)NSArray*注释;
@结束
谢谢,我已经准备好了,但是现在如果我试着用
@try {
_feed = [[NewsFeed alloc] initWithDictionary:obj error:nil];
}
@catch (NSException *e) {
NSLog(@"Parse error : %@ reason %@", [e name], [e reason]);
}
我得到了一个错误的属性协议声明,原因是不允许使用JSONModel属性协议,而不是JSONModel类
我的新闻提要是这样的
@interface NewsFeed : JSONModel
@property (nonatomic, strong) NSArray <NewsModel> *posts;
@end
@interface新闻提要:JSONModel
@属性(非原子、强)NSArray*柱;
@结束
像一个没有“评论”部分的魔术师一样工作
谢谢谢谢,我已经准备好了,但是现在如果我试着用
@try {
_feed = [[NewsFeed alloc] initWithDictionary:obj error:nil];
}
@catch (NSException *e) {
NSLog(@"Parse error : %@ reason %@", [e name], [e reason]);
}
我得到了一个错误的属性协议声明,原因是不允许使用JSONModel属性协议,而不是JSONModel类
我的新闻提要是这样的
@interface NewsFeed : JSONModel
@property (nonatomic, strong) NSArray <NewsModel> *posts;
@end
@interface新闻提要:JSONModel
@属性(非原子、强)NSArray*柱;
@结束
像一个没有“评论”部分的魔术师一样工作
感谢您对上述答案的补充,因为我还不能添加评论,您只需添加一个同名的空协议,如下所示:
@protocol CommentModel
@end
那么,正如这里所指出的,符号将不同于符号。第一个是JsonModel工作所需的协议声明,另一个是objc编译器助手声明。您可以将它们组合在一起,如同一示例中所述:
@property (nonatomic) NSArray<ProductModel *> <ProductModel> *products;
@property(非原子)NSArray*产品;
作为上述答案的补充,由于我还不能添加注释,您所要做的就是添加一个同名的空协议,如下所示:
@protocol CommentModel
@end
那么,正如这里所指出的,符号将不同于符号。第一个是JsonModel工作所需的协议声明,另一个是objc编译器助手声明。您可以将它们组合在一起,如同一示例中所述:
@property (nonatomic) NSArray<ProductModel *> <ProductModel> *products;
@property(非原子)NSArray*产品;
id
可以是字符串,NSDictionaly
的NSLog()
不会将所有字符串括在引号中。id
可以是字符串,NSDictionaly的NSLog()
不会将所有字符串括在引号中。我尝试了,但出现了“找不到“NewsModel”的协议声明”错误。。。在文档中,orderModel没有任何协议。谢谢您的尝试,但我有一个“找不到'新闻模型'的协议声明”错误。。。在文档中,orderModel没有任何协议。谢谢