Swift 从字符串中提取项目

Swift 从字符串中提取项目,swift,string,split,Swift,String,Split,我的JSON数据返回一个字符串,我现在很难处理这个字符串。它有一把这样的钥匙 "description": "<img src=\"http://www.testing.com/images/flowerOne.jpg\"><p>Erie, Pa., Aug 15, 2018 / 04:59 pm (<a href=\"http://www.testing.com\" target=\"_self\">CNA</a>).- Teachers in

我的JSON数据返回一个字符串,我现在很难处理这个字符串。它有一把这样的钥匙

"description": "<img src=\"http://www.testing.com/images/flowerOne.jpg\"><p>Erie, Pa., Aug 15, 2018 / 04:59 pm (<a href=\"http://www.testing.com\" target=\"_self\">CNA</a>).- Teachers in (name of town or district) and in communities across the nation will be in the spotlight on National Teacher Day..."
以及实际内容

Teachers in (name of town or district) and in communities across the nation will be in the spotlight on National Teacher Day...
在这种情况下,有人能帮我吗?

您可以使用解析响应的html字符串

例如,您的json

"description": "<img src=\"http://www.testing.com/images/flowerOne.jpg\"><p>Erie, Pa., Aug 15, 2018 / 04:59 pm (<a href=\"http://www.testing.com\" target=\"_self\">CNA</a>).- Teachers in (name of town or district) and in communities across the nation will be in the spotlight on National Teacher Day..."
然后,解析您的
htmlString
以查找图像url

do {
    let doc: Document = try SwiftSoup.parse(htmlString)
    if let imageLink = try doc.select("img").first()?.attr("src") {
        print("Your image url is ", imageLink)
    } else {
        print("Try break the html your self")
    }
} catch {
    print(error.localizedDescription)
}
别忘了导入雨燕组

import SwiftSoup

@马特,我很感激这个链接,但我问的是快速的问题,不是客观的。
do {
    let doc: Document = try SwiftSoup.parse(htmlString)
    if let imageLink = try doc.select("img").first()?.attr("src") {
        print("Your image url is ", imageLink)
    } else {
        print("Try break the html your self")
    }
} catch {
    print(error.localizedDescription)
}
import SwiftSoup