Javascript 无法打印Json对象

Javascript 无法打印Json对象,javascript,json,dweet.io,Javascript,Json,Dweet.io,下面的代码从循环中的URL获取的Json对象 问题是我似乎无法显示返回的Json数据。 我想显示物体的温度和湿度 有效的Json对象返回正常,但我无法在HTMLdiv中显示它 我看不到任何东西印在屏幕上 完整代码: <html> <head> <title>json loop</title> </head> <body> <script src="https://ajax.googleapis.com/ajax/lib

下面的代码从循环中的URL获取的Json对象

问题是我似乎无法显示返回的Json数据。 我想显示物体的温度和湿度

有效的Json对象返回正常,但我无法在HTMLdiv中显示它

我看不到任何东西印在屏幕上

完整代码:

<html>
<head>
<title>json loop</title>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
</script>

    <div id="container">
    <div id="div"></div>
        <div id="output">nothing yet</div>
    </div>

<script>
    var previous = null;
    var current = null;
    var data;
    setInterval(function() {
        $.getJSON(
            "https://dweet.io/get/latest/dweet/for/myesp8266", 
            function(json) {
                data = json; 
                current = JSON.stringify(data); 
                $("div").html(data);
                console.log(data);           
                if (previous && current && previous !== current) {
                    console.log('refresh');
                    location.reload();
                }
                previous = current;
        });                       
    }, 2000);   


var output = document.getElementById('output');
output.innerHTML = data ;

</script>
</body>
</html>   

json循环
还没有
var-previous=null;
无功电流=零;
var数据;
setInterval(函数(){
$.getJSON(
"https://dweet.io/get/latest/dweet/for/myesp8266", 
函数(json){
data=json;
current=JSON.stringify(数据);
$(“div”).html(数据);
控制台日志(数据);
如果(上一个和当前的和上一个!==当前的){
console.log('refresh');
location.reload();
}
先前=当前;
});                       
}, 2000);   
var output=document.getElementById('output');
output.innerHTML=数据;

你这样试过吗

setInterval(function() {
    $.getJSON("https://dweet.io/get/latest/dweet/for/myesp8266", 
    function(json) {
        data = json; 
        current = JSON.stringify(data); 
        //$("div").html(data);
        console.log(data);           
        if (previous && current && previous !== current) {
            console.log('refresh');
            location.reload();
        }
        previous = current;
        var output = document.getElementById('output');
        output.innerHTML = current ;
    });                       
}, 2000);  
编辑:


下面是一个关于如何工作的示例:

您没有将字符串放到HTML中。使用
当前
而不是
数据

data = json; 
current = JSON.stringify(data); 
$("div").html(current);
console.log(current);           
if (previous && current && previous !== current) {
    console.log('refresh');
    location.reload();
}
previous = current;
编辑 如果需要温度,请使用:

$("div").html(data.with[0].content.temperature);

谢谢,仍然没有显示任何内容…我想从Json对象中提取温度。我修改了我的答案,看一看。我试过了,但仍然没有显示任何内容…我想从Json对象中提取温度,请删除$(“div”).html(数据);