ios - 如何在 Objective C 中从 JSON 中获取 HTML 图像?
<p><p>这是我在带有表情符号的消息列中收到的 JSON:</p>
<pre><code><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>
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><pre><code>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 = *?src\\s*?=\\s*?['\"](.*?)['\"][\\s\\S]*?>)+?"
options:NSRegularExpressionCaseInsensitive
error:&error];
[regex enumerateMatchesInString:htmslStr
options:0
range:NSMakeRange(0, )
usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
NSString *img = ];
NSURL *candidateURL = ;
if (candidateURL && candidateURL.scheme && candidateURL.host)
{
NSLog(@"img src %@",img);
}
}];
</code></pre>
<p>最终的输出是</p>
<p> <a href="/image/ZsSnz.png" rel="noreferrer noopener nofollow"><img src="/image/ZsSnz.png" alt="enter image description here"/></a> </p></p>
<p style="font-size: 20px;">关于ios - 如何在 Objective C 中从 JSON 中获取 HTML 图像?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/32471760/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/32471760/
</a>
</p>
页:
[1]