【问题标题】:How to read string between to html node如何读取到 html 节点之间的字符串
【发布时间】:2016-05-09 09:09:43
【问题描述】:

我收到来自 JSON 网络服务的响应,并且我有一个节点“名称”。

{
    "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 标记。

【问题讨论】:

标签: ios objective-c json nsstring


【解决方案1】:

你可以检索你的字符串

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-05
      • 1970-01-01
      • 2018-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多