我用下一个代码获取JSON数据:

$.getJSON(
     "data.json",function foo(result) {
       $.each(result[1].data.children.slice(0, 10),
        function (i, post) {
          $("#content").append( '<br> HTML <br>' + post.data.body_html );
        }
      )
    }
 )

 <div id="content"></div>

其中包括一些字符串:&lt;&gt;,但未显示为常规html <>尝试使用.html()而不是.append()不起作用。

这是现场示例http://jsfiddle.net/u6yUN/

最佳答案

这是您要的信息:Complete JSFiddle Demo

var jsonRequestUrl = 'http://www.reddit.com/r/funny/comments/1v6rrq.json';
var decoder = $('<div />');
var decodedText = '';

$.getJSON(jsonRequestUrl, function foo(result) {
    var elements = result[1].data.children.slice(0, 10);

    $.each(elements, function (index, value) {
        decoder.html(value.data.body_html);
        decodedText += decoder.text();
    });

    $('#content').append(decodedText);
});

编辑:将其保留在此处作为一个简单示例。
// Encoded html
var encoded = '&lt;div style="background:#FF0"&gt;Hello World&lt;/div&gt;';

// Temp div to render html internally
var decode = $('<div />').html(encoded).text();

// Add rendered html to DOM
$('#output').append(decode);

DEMO

10-07 19:10
查看更多