YouTube 视频 API 片段标题包含 Next.js 中的特殊字符 [英] YouTube videos API snippet title contains special characters in Next.js

查看:17
本文介绍了YouTube 视频 API 片段标题包含 Next.js 中的特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得不包含特殊字符的正确视频片段标题.我正在使用 API:

https://www.googleapis.com/youtube/v3/search,

带有 snippet 部分.

目前,我得到了下面的 snippet.title:

<块引用>

我&#39;我要带她!!!与卡琳娜的堡垒之夜!

我希望得到这个标题:

<块引用>

我要抱她!!!与卡琳娜的堡垒之夜!

解决方案

首先,请确认您从 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&#39;M GONNA CARRY HER!!! Fortnite With Karina!

I expected this title instead:

I'm gonna carry her!!! Fortnite With Karina!

解决方案

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:

he (for "HTML entities") is a robust HTML entity encoder/decoder written in JavaScript. It supports all standardized named character references as per HTML, handles ambiguous ampersands and other edge cases just like a browser would, has an extensive test suite, and — contrary to many other JavaScript solutions — he handles astral Unicode symbols just fine. An online demo is available.

这篇关于YouTube 视频 API 片段标题包含 Next.js 中的特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆