简体   繁体   English

如何在反应原生中解析“

[英]how to parse " in react native

I am fetching some data from API and it is returning me results like "我正在从 API 获取一些数据,它返回的结果类似于" how can I convert it to normal form ' " '如何将其转换为正常形式'“'

const results = [
  { question: ' movie "The Revenant"?' },
  { question: ' game "Roblox" released?' },
  { question: '"A rainy Lithuanian / Is dancing as an Indian"' },
];

export default function App() {
  return (
    <View style={styles.container}>
      {results.map((q) => (
        <Text> {q.question} </Text>
      ))}
    </View>
  );
}

this is what I am getting这就是我得到的

在此处输入图像描述

one way you can use replace in client side like that:您可以像这样在客户端使用替换的一种方法:

  • .replace(/&quot;/g, '"')

or other way you can save quot in database and send from backend side like format:或其他方式您可以将quot保存在数据库中并从后端发送,如格式:

  • question: ' movie '''The Revenant'''?'

I hope that's Helpful我希望这有帮助

There isn't a built in way in javascript as far as I know.据我所知,javascript 中没有内置方式。 I have used the he library in the past to make it easy, this might suit you.我过去曾使用he 库来简化它,这可能适合你。

Best way is probably just through a string replace as mentioned in other answer.最好的方法可能只是通过其他答案中提到的字符串替换。 Full list of html character entities found here .此处找到 html 字符实体的完整列表。

Barring that, you can always add an element to the dom and set the inner html but this can be dangerous as it can introduce XSS vulnerabilities as you can inject javacript code this way.除此之外,您始终可以向 dom 添加一个元素并设置内部 html 但这可能很危险,因为它可能会引入 XSS 漏洞,因为您可以通过这种方式注入 javacript 代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM