如何读取 html 节点之间的字符串

How to read string between to html node

我收到来自 JSON 网络服务的响应并且我有一个节点 "name"。

{
    "name": "<style>b\n {\n  font-family:'helvetica';\n  line-height: 200%;\n  text-align: justify;\n } \n </style><b>CORN IDLIS</b><br/>"
}

我正在尝试获取介于 CORN IDLIS 之间的食物名称。

所以任何人都请建议我如何从该节点读取或删除所有 html 标签。

您可以检索您的字符串

NSString *htmlStr = responseDic[@"name"];
NSArray *tempArray = [htmlStr componentsSeparatedByString:@"<b>"];
NSArray *tempArray1 = [tempArray[1] componentsSeparatedByString:@"</b>"];
NSString *yourString = [tempArray1 firstObject];

在代码下面正常工作,htmlstring 是你的 html

NSAttributedString *tmp =[[NSAttributedString alloc] initWithData:[htmlstring dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]} documentAttributes:nil error:nil];