首页 > 解决方案 > How to fix text encoding errors in title and description from Youtube Api v3?

问题描述

I'm a novice React web developer, and i'm building a simple web React App which uses Youtube API v3, in order to render and display video according to the user search.

When i make a call from Youtube API V3, I have some issues related to some characters displayed in my title and description.

I've correctly added meta charSet="UTF-8" or even meta charset="utf-8 in Head inside my index.html, but this error stills not fixed.

const VideoDetail = ({ video }) => {
  if (!video) {
    return <div>Loading...</div>;
  }

  const videoSrc = `https://www.youtube.com/embed/${video.id.videoId}`;

  return (
    <div>
      <div className="ui embed">
        <iframe src={videoSrc} />
      </div>
      <div className="ui segment">
        <h4>{video.snippet.title}</h4>
        <p>{video.snippet.description}</p>
      </div>
    </div>
  );
};

For example, the description of a video is rendered like this : my Beautiful Home &amp my wonderful car.

Instead, The sentence should actually be like this: my Beautiful Home and my wonderful car.

标签: javascriptreactjs

解决方案


推荐阅读