Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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
Javascript 如何处理Json发送的html代码?_Javascript_Angularjs_Json - Fatal编程技术网

Javascript 如何处理Json发送的html代码?

Javascript 如何处理Json发送的html代码?,javascript,angularjs,json,Javascript,Angularjs,Json,我有来自json的数据,它是html代码,我怎么能像html一样打印它,因为它似乎只打印为字符串: "content": "Más pruebas\u003cbr /\u003e\n\u003cbr /\u003e\n\u003cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003e\n\u003ca href=\"https://2.bp.blogspot.com/-CK43Mn516s4/WEmW

我有来自json的数据,它是html代码,我怎么能像html一样打印它,因为它似乎只打印为字符串:

   "content": "Más pruebas\u003cbr /\u003e\n\u003cbr /\u003e\n\u003cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003e\n\u003ca href=\"https://2.bp.blogspot.com/-CK43Mn516s4/WEmWGS9eoaI/AAAAAAAASg0/k4213387TNA0XInyTNgqaqEn4YYanzCZgCLcB/s1600/Monsters-Inc-Concept-Art.jpg\" imageanchor=\"1\" style=\"clear: left; float: left; margin-bottom: 1em; margin-right: 1em;\"\u003e\u003cimg border=\"0\" height=\"174\" src=\"https://2.bp.blogspot.com/-CK43Mn516s4/WEmWGS9eoaI/AAAAAAAASg0/k4213387TNA0XInyTNgqaqEn4YYanzCZgCLcB/s200/Monsters-Inc-Concept-Art.jpg\" width=\"200\" /\u003e\u003c/a\u003e\u003c/div\u003e\n\u003ca href=\"http://google.com/\"\u003eGoogle\u003c/a\u003e",
我使用的是angularjs 1.x


谢谢大家!

当您从数据源接收HTML代码时,您应该使用$sce服务对其进行转义。使用

$sce.trustAsHtml(data)
下面是一个plunker,用于演示数据,然后将字符串显示为HTML:

使用:

<div html="scopeVariable"></div>


您需要使用
JSON.parse
您能提供获取和打印此字符串的代码吗?可能的重复项似乎他只是想打印,而不是注入到他的DOM中。这里有一个能够格式化这些东西的工具:对
console.log的简单调用似乎可以很好地打印输出。。。