这是我在带有表情符号的消息列中收到的 JSON:
<span class=\"atwho-inserted\"><img src=\"https://assets-cdn.github.com/images/icons/emoji/smile.png\" height=\"20\" width=\"20\"></span> <span class=\"atwho-inserted\"><img src=\"https://assets-cdn.github.com/images/icons/emoji/person_with_blond_hair.png\" height=\"20\" width=\"20\"></span>
Best Answer-推荐答案 strong>
NSString *htmslStr=@"<span class=\"atwho-inserted\"><img src=\"https://assets-cdn.github.com/images/icons/emoji/smile.png\" height=\"20\" width=\"20\"></span> <span class=\"atwho-inserted\"><img src=\"https://assets-cdn.github.com/images/icons/emoji/person_with_blond_hair.png\" height=\"20\" width=\"20\"></span>";
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern"(<img\\s[\\s\\S]*?src\\s*?=\\s*?['\"](.*?)['\"][\\s\\S]*?>)+?"
options:NSRegularExpressionCaseInsensitive
error:&error];
[regex enumerateMatchesInString:htmslStr
options:0
range:NSMakeRange(0, [htmslStr length])
usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
NSString *img = [htmslStr substringWithRange:[result rangeAtIndex:2]];
NSURL *candidateURL = [NSURL URLWithString:img];
if (candidateURL && candidateURL.scheme && candidateURL.host)
{
NSLog(@"img src %@",img);
}
}];
最终的输出是
关于ios - 如何在 Objective C 中从 JSON 中获取 HTML 图像?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/32471760/
|