这是什么编码?我应该使用什么脚本对其进行解码?

时间:2017-06-26 10:10:58

标签: ios swift xcode formatting

我有一个编码字符串,我必须转换为具有HTML标记的表单并在webview中显示它。我所拥有的编码数据具有以下格式: -

有+ A +宠物+相当+喜欢+育儿%2C +你+只是+不能+站+中+机会+是+消失+在+它们。+仍然%2C +十分+常+它+出现+是+您+不能+拥有+你的+宠物+左右+到处+那么+你+需要+到+住房+他们+别处+为A +,而+但是+在+ +端+ +在+一天%的2C +一个+一定+承认+是+它是+漂亮+硬盘+到+信托+人+有+我们+毛茸茸+婴儿。+谁+知道+他们+比+我们更好+ %2C +自己+习惯%2C +饮食+单%2C +气质+和+社会+倾向%3F%0D%0A%0D%0AIt +是+,因为+ +本+非常+理由+是+我们在+ %3CA + HREF%3D%22https%3A%2F%2Fwww.whatsuplife.in%2Fnoida%22 +靶%3D%22_blank%22 +相对%3D%22noopener%22%3EWhat%92S +向上+诺依+为+共享%3C%2FA%3E +与+您+的+ 5个+宠物+寄宿+设备+这+在+目录+你+可以+实际上+信任。%0D%0A%3CH 4%3E%3Cstrong%3EThe +狗+度假村%2C +诺伊达+%3C%2Fstrong%3E%3C%2Fh4%3E%0D%0AAt +在+狗+酒店+诺伊达%2C +被+保证+是+你的+宠物+会+被+关心+为+通过彻底+专业+。+%A0They +度假+拥有+的+ A + 10%2C000 +平方+英尺+房屋+区域+地方+约5000+平方+ .ft +是+宽+开放+绿色+区域+到+使+你的+宠物+住宿+俏皮+和+欢呼。+在+最好的方面+约+在+地点+是+是+有是+完整+医疗+保健+和+行为+逮捕的+宠物+ +为+它们+拥有+兽+医生%2C +狗+教练员%2C +和+其他+宠物+护理+专业知识。%0D%0A%0D%的+ A +专用+团队+ 0A%3CA + HREF%3D%22https%3A%2F%2Fwww.whatsuplife.in%2Fnoida%2Fblog%2Fwp含量%2Fuploads%2F2017%2F06%2FDog-度假noida.png%22%3E%3Cimg +类% 3D%22aligncenter + WP-图像-4902 +大小满%22 + SRC%3D%22https%3A%2F%2Fwww.whatsuplife.in%2Fnoida%2Fblog%2Fwp含量%2Fuploads%2F2017%2F06%2FDog-度假村noida.png%22 + ALT%3D%22Dog +景区+诺依%22 +宽度%3D%221052%22 +高度%3D%22326 22%+%2F%3E%3C%2FA%3E%0D 0A%%0D %0A%3Cstrong%3EAddress%3A%A0 +部门+ 112%2C +诺依%3C%2Fstrong%3E%0D%0A%3Cstrong%3E +联系%3A + 9911782646%3C%2Fstrong%3E%0D%0A%3CH 4 %3E%3Cstrong%3EBest + PET +登机+%3C%2Fstrong%3E%3C%2Fh4%3E%0D%0AThey +是+确实+一个+的+的+高度+额定+和+正+审查+宠物+登机+设施+在+诺伊达+不只是+ + +为​​狗+ +,但他们有+ + A + friendl Y + +宠物+护理+的普罗维登斯+和+日+登机+为+其他+宠物服务+ +喜欢+鱼%2C +鸟%2C +豚鼠+猪%2C +仓鼠%2C +猫%2C +和+其他+为+以及%A0 +创造+的+想法是+%91no笼%92 +免费+空间+为心爱+宠物+中+开发+由+卡佛力+蛙+巴德瓦杰+和+ Yashraj +巴德瓦杰。+在+ +最佳+宠物+寄宿%2C +在+重点是+上+制作+你的+宠物+社交+和+拥有+ A +免费+会+徘徊+的+在+宽+空间+他们+相信+在+出租+的+独特+概念+在+ A +训练有素+狗+这+说+至+在+的+%91alpha%92 + +其他+宠物+狗%2C中这个+ + +保持在+礼仪+ +所有在+时间。%0D 0A%%0D 0A%%3CA + HREF%3D%22https%3A%2F%2Fwww.whatsuplife.in%2Fnoida%2Fblog%2Fwp含量% 2Fuploads%2F2017%2F06%2Fbest-PET-boarding.jpg%22%3E%3Cimg +类%3D%22aligncenter + WP-图像-4903 +大小满%22 + SRC%3D%22https%3A%2F%2Fwww。 whatsuplife.in%2Fnoida%2Fblog%2Fwp含量%2Fuploads%2F2017%2F06%2Fbest-PET-boarding.jpg%22 + ALT%3D%22best +宠物+登机+诺依%22 +宽度%3D%22960 22%+高度%3D%22489 22%+%2F%3E%3C%2FA%3E%0D 0A%%0D 0A%%3Cstrong%3EAddress%3A + B + 14 + 1 +嗡Icron的+ 2%2C +大+诺依%3C%2Fstrong%3E%0D%0A%3Cstrong%3E +电话%3A + 09711951179%3C%2Fstrong%3E%0D%0A%3CH 4%3E%3Cstrong%3EPet +首页+事务+节+登机+%3C%2Fstrong%3E%3C%2Fh4%3E%0D%0A%3CA +风格%3D%22font尺寸%3A + 14px的%3B +字体家庭%3A +%27Open +三世%27% 2C + Arial字体%2C +无衬线%3B +彩色%3A +%2319232d%3B +文字修饰行%3A +下划线%3B%22 + HREF%3D%22https%3A%2F%2Fwww.whatsuplife.in% 2Fnoida%2Fblog%2Fwp含量%2Fuploads%2F2017%2F06%2Fpet-家庭事务天care.jpg%22%3E%3Cimg +类%3D%22alignright + WP-图像4906 +尺寸全%22 +风格%3D%22font尺寸%3A + 14px的%3B%22 + SRC%3D%22https%3A%2F%2Fwww.whatsuplife.in%2Fnoida%2Fblog%2Fwp含量%2Fuploads%2F2017%2F06%2Fpet-主页 - 事务天care.jpg%22 + ALT%3D%22pet +登机+在+诺依%22 +宽度%3D%22350%22 +高度%3D%22263 22%+%2F%3E%3C%2FA%3E %0D%0A%0D%0APet +首页+事务+喜欢+ A +英镑+口碑+在+宠物+护理+行业+和是+一个+的+在+诺伊达+卓越+服务+ +在+在登机+%2C +有+是+专业+ +谁懂+的+需要+你的+宠物+ +和+ +还你+ prefere NCES +约+在+专用+服务+你+需要+为你+宠物+宠物+护理+系统+是+以及+计划+为+计时+和+下+在+护理+餐+和+医药+ +宠物+护理+专家+此处。%0D%0A%0D%0A%3Cstrong%3EAddress%3A%A0 + SUPERTECH +开普敦%2C +部门+ 74%2C +诺依。%3C%2Fstrong%3E%0D %0A%3Cstrong%3E +电话%3A + 09873204636%3C%2Fstrong%3E%0D%0A%3CH 4%3E%3Cstrong%3EClean +可爱+%3C%2Fstrong%3E%3C%2Fh4%3E%0D%0AWith +他们+狗+日+护理+和+宠物+度假+家庭%2C +清洁+ 10%2C000 +平方+尺+宽+空格+ +可爱+中+知道+到+服务+所有+尺寸%2C +各类%2C +品种%2C +和+的+宠物年龄+。+它们+是+最大的+和+最好的寄宿+工厂+不但+ +中+诺伊达+而且+也+在+ NCR +清洁+可爱的是+管理+通过+ A +高度+技能+狗+操作+团队+产品+宠物+修饰+服务%2C +休闲+活动%2C +健康+关心%2C +疗法%2C +宠物+育儿辅导%2C +狗+行为+管理%2C +护肤+护理%2C +狗+修复+和+其实%2C +什么不能%0D%0A%0D%0A%3CA + HREF%3D%22https%3A。 %2F%2Fwww.whatsuplife.in%2Fnoida%2Fblog%2Fwp含量%2Fuploads%2F2017%2F06%2FBoarding-拉RGE-File.jpg%22%3E%3Cimg +类%3D%22aligncenter + WP-图像-4907 +尺寸大22%+的src%3D%22https%3A%2F%2Fwww.whatsuplife.in%2Fnoida%2Fblog% 2Fwp含量%2Fuploads%2F2017%2F06%2FBoarding-大文件的1024x682.jpg%22 + ALT%3D%22dog +登机+在+诺依%22 +宽度%3D%22702%22 +高度%3D%22468% 22 +%2F%3E%3C%2FA%3E%0D%0A%0D%0A%26nbsp%3B%0D%0A%0D%0A%3Cstrong%3EAddress%3A%A0 +部门+ 112%2C +诺依%3C %2Fstrong%3E%0D%0A%3Cstrong%3E +电话%3A + 08076548163%3C%2Fstrong%3E%0D%0A%3CH 4%3E%3Cstrong%3EGoDogee +宠物+服务+%3C%2Fstrong%3E%3C%2Fh4 %3E%0D%0AGoDogee是+一个++的+印度%92S +龙头+宠物+护理+服务+提供+宠物+日+护理%2C +宠物+酒店%2C + PET +美容%2C +宠物+接种%2C +宠物+治疗%2C +宠物+匹配+和+其他+有趣+和+独特+排序+ +的服务。0D%0A%0D%0A%%3Cimg +类%3D%22aligncenter +大小 - 全+ WP-图像-4905%22 + SRC%3D%22https%3A%2F%2Fwww.whatsuplife.in%2Fnoida%2Fblog%2Fwp含量%2Fuploads%2F2017%2F06%2Fgodogee.jpg%22 + ALT%3D% 22%22 +宽度%3D%221920%22 +高度%3D%22790 22%+%2F%3E%0D 0A%%0D 0A%%3Cstrong%3EAddress%3A + J-10%2C +诺依+路%2C + H +块%2C +部门+ 8%2C +诺依%3C%2Fstrong%3E%0D%0A%3Cstrong%3E +电话%3A + 09910664343%3C%2Fstrong% 3E

这是什么类型的格式,如何将其转换为带有html标签的文本?

我目前正在使用这种方法,但我得到的是零回报值:

func urlDecode(_ htmlString: String) -> String {

    var decodedURL = htmlString.replacingOccurrences(of: "+", with: " ")
    decodedURL = decodedURL.removingPercentEncoding!
    return decodedURL
}

2 个答案:

答案 0 :(得分:0)

来自苹果,

  

删除了百分比编码序列的新字符串,如果是,则为nil   接收器包含无效的百分比编码序列。您必须调用   此方法仅适用于您知道为百分比编码的字符串。   在非百分比编码的字符串上调用此方法可能会导致   将百分比字符误解为a的开头   百分比编码序列。

由于removingPercentEncoding无法识别您的某些百分比编码,因此您获得了nil。我将其粘贴到online parser上,发现%A0和%92似乎是可疑的。

答案 1 :(得分:0)

所以你得到nil,这意味着你的字符串中有些东西是无效的。我们怎么能找到什么?嗯,它肯定不是空格,所以让我们把你的字符串分成"单词":

var decodedURL = htmlString.replacingOccurrences(of: "+", with: " ")
let chunks = decodedURL.components(separatedBy: " ")

现在尝试解码每个"字"并看看哪些失败了:

for chunk in chunks
{
   let decoded = chunk.removingPercentEncoding
   if decoded == nil
   {
      print("\(chunk)")
   }
}

此输出:

rel%3D%22noopener%22%3EWhat%92s
%A0They
%2F%3E%3C%2Fa%3E%0D%0A%0D%0A%3Cstrong%3EAddress%3A%A0
well.%A0
%91no-cage%92
%91alpha%92
here.%0D%0A%0D%0A%3Cstrong%3EAddress%3A%A0
%2F%3E%3C%2Fa%3E%0D%0A%0D%0A%26nbsp%3B%0D%0A%0D%0A%3Cstrong%3EAddress%3A%A0
India%92s

现在removingPercentEncoding解码UTF-8,因此检查每个%序列以查看它们是否有效UTF-8显示%91,%92& %A0不是。但它们是有效的Windows-1252编码 - 单个卷曲引号和不间断的空格。

所以你需要将字符串解码为Windows-1252而不是UTF-8。是时候查看文档......

HTH