EGYBlogPost 用 json 获取博客文章的简单方式。
Cocoapods
用法
NSURL *EGYBlog = [NSURL URLWithString:@"JSON-API-URL"];
NSData *EGYJSON = [NSData dataWithContentsOfURL:EGYBlog];
NSError *ERROR = nil;
NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:EGYJSON options:0 error:&ERROR];
NSMutableArray *EGYBLOGPOSTS = [NSMutableArray array];
NSArray *blogPostsArray = [dataDictionary objectForKey:@"posts"];
for (NSDictionary *bpDictionary in blogPostsArray) {
EGYBlogPost *blogPost = [EGYBlogPost egyBlogPostWithTitle:[bpDictionary objectForKey:@"title"]];
blogPost.author = [bpDictionary objectForKey:@"author"];
blogPost.thumbnail = [bpDictionary objectForKey:@"thumbnail"];
blogPost.date = [bpDictionary objectForKey:@"date"];
blogPost.url = [NSURL URLWithString:[bpDictionary objectForKey:@"url"]];
[EGYBLOGPOSTS addObject:blogPost];
致谢
EGYBlogPost 由 Mokhles Hussien 带来 @iMokhles