问题描述
我想获得不包含特殊字符的正确视频片段标题.我正在使用 API:
https://www.googleapis.com/youtube/v3/search
,
带有 snippet
部分.
目前,我得到了下面的 snippet.title
:
我'我要背着她!!!堡垒之夜与卡琳娜!
我期待这个标题:
我要抱她!!!堡垒之夜与卡琳娜!
首先,请承认您从 API 中获得的内容不是(引用您的)特殊字符.
从技术上讲,这些字符序列是
he(用于HTML 实体")是一个用 JavaScript 编写的强大的 HTML 实体编码器/解码器.它支持所有符合 HTML 的标准化命名字符引用, 处理模糊的&符号和其他边缘情况就像浏览器一样,具有广泛的测试套件,并且——与许多其他 JavaScript 解决方案相反——he 可以很好地处理星体 Unicode 符号.提供在线演示.
I want to get the right video snippet title that doesn't include special characters.I am using the API:
https://www.googleapis.com/youtube/v3/search
,
with the part snippet
.
Currently, I am getting the snippet.title
below:
I expected this title instead:
First, please acknowledge that what you've got from the API are not (quote from you) special characters.
To be technically precise, those sequence of characters are HTML character references, also known as HTML entities.
The behavior you've encountered is a well-known issue of the API, for which there's no other solution that I know of, except that you yourself have to substitute those HTML entities for the actual characters that they stand for.
Now, I recommend against an ad hoc solution; that is I do recommend you to employ well-written well-tested well-known libraries that derive their non-trivial solution from carefully implemented code conforming to the current HTML standard.
In my opinion, Mathias Bynens' library is evidently a tool that meets each of the criteria I mentioned above:
这篇关于YouTube 视频 API 片段标题在 Next.js 中包含特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!