I’m using JSONMODEl (https://github.com/icanzilb/JSONModel) to parse a wordpress JSON FEED (with json-api).
Everything go’s well except if I want the “comments”.
my feed is like that :
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";
}
);
so I try to make my “newsmodel” like that :
#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
and my commentmodel like that
#import "JSONModel.h"
@interface CommentModel : JSONModel
@property (assign, nonatomic) int id;
@property (strong, nonatomic) NSString* name;
@property (assign, nonatomic) NSString* content;
@end
But When I try to build my app, my “feed” is empty.
if I comment the “comment” part of the news model, I got the content….
I think I’m stuck somewhere, but where ! If someone ave an idea 🙂
Many thanks
comments
is an array, not a single comment, notice the top level(
and)
which designate an array in aNSDictionary
NSLog()
. Inside of the is an array element designated by{
and}
.But the
NewsModel
hascomments
defined as a single comment (CommentModel
), not an array. it should probably be declared:In the docs see Model collections and how
products
is handled.You will have to declare a
protocol
, see the exampleprotocol
at the top of the “Model collections” examples.Above:
Thanks, got it to build, but now If i try to alloc it with
I got a Bad property protocol declaration reason is not allowed JSONModel property protocol, and not a JSONModel class.
my news feed is like that
And work like a charme without the “comment” part…
Thanks
As an addition to the answers above, since I can’t add a comment yet, all you have to do, is add an empty protocol with the same name, like this:
Then, as noted here JsonModel documentation, notation would be different than a notation. The first one is a protocol declaration needed for JsonModel to work, the other one is an objc compiler helper declaration. You can combine them as noted in the same example: