Android 如何从json中删除html标记? [{“id”:1,“header”:“Wien&8217;s常数的单位是“
”,“qOptions”:“[{“OptionNo\”:“a\”,“ValueHtml\”,“a)Android 如何从json中删除html标记? [{“id”:1,“header”:“Wien&8217;s常数的单位是“,android,json,Android,Json,”,“qOptions”:“[{“OptionNo\”:“a\”,“ValueHtml\”,“a)
页边距底部:0in;页边距底部:.0001pt\\”>您可以使用正则表达式删除它们-
[{"id":1,"header":"<tr><td style=\"width:5.36%\" width=\"5%\" valign=\"top\"></td><td style=\"width:94.48%\" width=\"94%\" colspan=\"2\" valign=\"top\"> <p style=\"margin-bottom:0in;margin-bottom:.0001pt\"><span style='font-family:\"Cambria Math\",serif'>The unit of Wien’s constant </span><span style='font-size:11.0ptline-height:115%font-family:\"Calibri\",sans-serifposition:relativetop:4.5pt'><img width=\"8\" height=\"20\" src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAUAQMAAACK1e4oAAAAAXNSR0IArs4c6QAAAAZQTFRFAAAAAAAApWe5zwAAAAF0Uk5TAEDm2GYAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAZdEVYdFNvZnR3YXJlAE1pY3Jvc29mdCBPZmZpY2V/7TVxAAAAH0lEQVQYV2NgAAMDBgEg1GMwYlACQjcGF4YKiAQMAAAqagH3u8+wVwAAAABJRU5ErkJggg==\"></span><span style='font-family:\"Cambria Math\",serif'> is </span></p> </td><td style width=\"0%\" colspan=\"2\"><p> </p></td></tr>","qOptions":"[{\"OptionNo\":\"a\",\"ValueHtml\":\"<tr><td style=\\\"width:5.36%\\\" width=\\\"5%\\\" valign=\\\"top\\\"> <p><span style='font-family:\\\"Cambria\\\",serif'> </span></p> </td><td style=\\\"width:2.4%\\\" width=\\\"2%\\\"> <p><span style='font-family:\\\"Cambria\\\",serif'>a)</span></p> </td><td style=\\\"width:92.14%\\\" width=\\\"92%\\\" colspan=\\\"2\\\"> <p style=\\\"margin-bottom:0in;margin-bottom:.0001pt\\\"><span style='font-size:11.0ptline-height:115%font-family:\\\"Calibri\\\",sans-serif'><img width=\\\"65\\\" height=\\\"20\\\" src=\\\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEEAAAAUAQMAAADoesJCAAAAAXNSR0IArs4c6QAAAAZQTFRFAAAAAAAApWe5zwAAAAF0Uk5TAEDm2GYAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAZdEVYdFNvZnR3YXJlAE1pY3Jvc29mdCBPZmZpY2V/7TVxAAAAaUlEQVQYV2NgwAH4GBiYIFJCDAxsDAyPLIAClge4GBicBBjkWwT6TzUwuAowMHAIMsgDWYKbGQSEQDpUFc40yIkwMDMwaCzoaGCQAZkAZgGNgbIEQSwBB6CYQAOI5Xj3AIPlAVwOIU4cAGqKE6T9p+R5AAAAAElFTkSuQmCC\\\"></span></p> </td><td style width=\\\"0%\\\"><p> </p></td></tr>\"},{\"OptionNo\":\"b\",\"ValueHtml\":\"<tr><td style=\\\"width:5.36%\\\" width=\\\"5%\\\" valign=\\\"top\\\"> <p><span style='font-family:\\\"Cambria\\\",serif'> </span></p> </td><td style=\\\"width:2.4%\\\" width=\\\"2%\\\"> <p><span style='font-family:\\\"Cambria\\\",serif'>b)</span></p> </td><td style=\\\"width:92.14%\\\" width=\\\"92%\\\" colspan=\\\"2\\\"> <p style=\\\"margin-bottom:0in;margin-bottom:.0001pt\\\"><span style='font-size:11.0ptline-height:115%font-family:\\\"Calibri\\\",sans-serif'><img width=\\\"51\\\" height=\\\"20\\\" src=\\\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADMAAAAUAQMAAAAaxpfnAAAAAXNSR0IArs4c6QAAAAZQTFRFAAAAAAAApWe5zwAAAAF0Uk5TAEDm2GYAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAZdEVYdFNvZnR3YXJlAE1pY3Jvc29mdCBPZmZpY2V/7TVxAAAAS0lEQVQYV2NgwACMQJEGIGZnYGAG0Yx8BSA++0MW5Q9gPosDkJ9zgJGlAUgbK7AfZWB+wKCkANLAAKKB4hDaAUorAOnyAgagOSQDAOKkDOJJ7pIYAAAAAElFTkSuQmCC\\\"></span></p> </td><td style width=\\\"0%\\\"><p> </p></td></tr>\"},{\"OptionNo\":\"c\",\"ValueHtml\":\"<tr><td style=\\\"width:5.36%\\\" width=\\\"5%\\\" valign=\\\"top\\\"> <p><span style='font-family:\\\"Cambria\\\",serif'> </span></p> </td><td style=\\\"width:2.4%\\\" width=\\\"2%\\\"> <p><span style='font-family:\\\"Cambria\\\",serif'>c)</span></p> </td><td style=\\\"width:92.14%\\\" width=\\\"92%\\\" colspan=\\\"2\\\"> <p style=\\\"margin-bottom:0in;margin-bottom:.0001pt\\\"><span style='font-size:11.0ptline-height:115%font-family:\\\"Calibri\\\",sans-serif'><img width=\\\"32\\\" height=\\\"20\\\"
var myString='[{“id”:1,“header”:“Test”}]';
var newString=myString.replace(//gm',);
代码的完整示例如下-
var myString = '[{"id":1,"header":"<tr><td style=\"width:5.36%\" width=\"5%\">Test</td>"}]';
var newString = myString.replace(/<(?:.|\n)*?>/gm, '');
$(文档).ready(函数(){
$(“#测试”)。单击(函数(){
$.get(”http://qbankapi.exambash.com/api/exam/GetAllTestquestions?testid=1,功能(数据、状态){
var str=JSON.stringify(数据);
警报(str);//来自URL的json
var newString=str.replace(//gm',);
警报(新闻字符串);//带有替换HTML标记的字符串
var newStr=JSON.parse(newString);//要使用的新JSON
console.log(newStr);
});
});
});
点击
希望这对你有帮助。你可以试试这个
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("#test").click(function(){
$.get("http://qbankapi.exambash.com/api/exam/GetAllTestquestions?testid=1", function(data, status){
var str = JSON.stringify(data);
alert(str); // json from URL
var newString = str.replace(/<(?:.|\n)*?>/gm, '');
alert(newString); // string with replaced HTML tags
var newStr = JSON.parse(newString); // new JSON to use
console.log(newStr);
});
});
});
</script>
<script>
</script>
</head>
<body>
<button id="test" >Click</button>
</body>
</html>
myHtmlString.replaceAll(“s///g”,“”);
Html.fromHtml(htmlSrc.toString();
这是一种糟糕的方法……您必须通过json验证来验证json响应
尝试从后端更改响应。。。
甚至可以在java中用null替换字符串来替换[“,;,/…等…”
- html=html.replaceAll(“,”);//删除中的所有项目 括号 html=html.replaceAll(“,”);//删除所有连接到最后一个括号中的项 html=html.replaceAll(“,”); html=html.replaceAll(&,“”)
myHtmlString.replaceAll("s/<(.*?)>//g","");
Html.fromHtml(htmlSrc).toString();