Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何从json中删除html标记? [{“id”:1,“header”:“Wien&8217;s常数的单位是“_Android_Json - Fatal编程技术网

Android 如何从json中删除html标记? [{“id”:1,“header”:“Wien&8217;s常数的单位是“

Android 如何从json中删除html标记? [{“id”:1,“header”:“Wien&8217;s常数的单位是“,android,json,Android,Json,”,“qOptions”:“[{“OptionNo\”:“a\”,“ValueHtml\”,“a)

”,“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&#8217;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'>&nbsp;is </span></p>  </td><td style width=\"0%\" colspan=\"2\"><p>&nbsp;</p></td></tr>","qOptions":"[{\"OptionNo\":\"a\",\"ValueHtml\":\"<tr><td style=\\\"width:5.36%\\\" width=\\\"5%\\\" valign=\\\"top\\\">  <p><span style='font-family:\\\"Cambria\\\",serif'>&nbsp;</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>&nbsp;</p></td></tr>\"},{\"OptionNo\":\"b\",\"ValueHtml\":\"<tr><td style=\\\"width:5.36%\\\" width=\\\"5%\\\" valign=\\\"top\\\">  <p><span style='font-family:\\\"Cambria\\\",serif'>&nbsp;</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>&nbsp;</p></td></tr>\"},{\"OptionNo\":\"c\",\"ValueHtml\":\"<tr><td style=\\\"width:5.36%\\\" width=\\\"5%\\\" valign=\\\"top\\\">  <p><span style='font-family:\\\"Cambria\\\",serif'>&nbsp;</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(&,“”)

首先发布您的完整json响应此json无效请您的json提供商(即后端程序员)以纯json格式发送数据,而不包括html标记。谢谢Rohit,您能告诉我您是如何将其称为无效的吗?还是不可能删除html标记Hanks devutkarsh。它有一些等式,因此我的后端开发人员说他仅使用tagsdude传递数据我从json获取数据如何将其设置为字符串。我尝试过此方法,但不起作用如果需要,我可以发送我的json链接alsoUse json.stringify()将json转换为Stirng。然后替换HTML,然后执行json.parse()转换回JSON并使用它。当然,共享它。将它添加到您的问题中。我会看一看并让您知道。接受它的答案会有所帮助。
myHtmlString.replaceAll("s/<(.*?)>//g","");
Html.fromHtml(htmlSrc).toString();