skip to Main Content

I am making a simple quiz web app in React and using an API to fetch questions. But when I display those questions on screen I get weird characters. How to resolve this issue?

I fetched the data as
`

fetch("https://opentdb.com/api.php?amount=5")
    .then(res=>res.json())
    .then(data=>setQuesArr(data.results))

`

I am displaying the question in this manner

`

<p>{JSON.parse(JSON.stringify(props.question))}</p>

`

2

Answers


  1. Are you referring to the symbols such as &quot;? These are quotation marks, you can replace them before you put it into your paragraph tag, something along the lines of this:

    var text = text.replace(/&quot;/g, '"');
    

    This will replace all instances of your &quot with the " character (you can modify this for other tags that you come across as well)

    Login or Signup to reply.
  2. fetch("https://opentdb.com/api.php?amount=5")
    .then(res=>res.json())
    .then(data=>setQuesArr(data))
    

    You can try with this. just remove the .results

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search