【发布时间】:2014-02-26 06:03:07
【问题描述】:
我目前正在使用 AFNetworking 从 Wordpress API 使用 JSON Web 服务。
这是我使用的格式:
[
{
id: 4,
title: "post1",
permalink: “http://www.example.com/test-post”,
content: “blah blah blah blah blah <iframe src="//player.vimeo.com/video/1010101?title=0&byline=0&portrait=0&color=ff5546" height="638" width="850" allowfullscreen="" frameborder="0"></iframe> more text blah blah <a href="http://example.com/wp-content/uploads/2014/01/testpic.png"><img class="aligncenter size-full wp-image-1180" alt="testpic" src="http://example.co/wp-content/uploads/2014/01/testpic.png" width="850" height="611" /></a>",
excerpt: " blah blah blah",
date: "2014-02-24 23:32:19",
author: "admin",
categories:
[
"Uncategorized"
],
tags: [ ]
},
{
id: 1,
title: "Hello world!",
permalink: “http://www.example.com/test-post”,
content: "Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!",
excerpt: "Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!",
date: "2014-02-24 22:48:12",
author: "admin",
categories:
[
"Uncategorized"
],
tags: [ ]
}
]
我的消费方式如下:
-(void)makeWordpressRequest
{
NSURL *URL = [NSURL URLWithString:@"http://example.com/feed/json"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]
initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
self.wordpress = responseObject;
[self.tableView reloadData];
NSLog(@"%@", responseObject);
} failure:nil];
[operation start];
}
现在这是我的问题.. 我可以成功解析并显示 JSON 的“内容”字符串,但我还没有弄清楚如何从该字符串中删除视频的“iframe”和“a href”到显示它。
有没有直接嵌入它们?或者我可以以编程方式将它们从 JSON 字符串中拆分出来,然后以另一种方式嵌入它们?我目前正在使用 UITextView 来显示@“内容”。
编辑:
不仅可以删除 HTML,还可以在可能的情况下正确嵌入它..
感谢您的帮助
【问题讨论】:
标签: ios objective-c json parsing