如何通过JQUERY将JSON转换为HTML?

问题描述 投票:0回答:1

我正在尝试将一些JSON数据解析为网页。我一直收到一个“未定义”的错误,应该显示JQUERY变量。我已经扫描过以前的解决方案;不幸的是,因为我是新手,所以他们都是我的头脑。知道我做错了什么吗?

这是我的JSON内容:

[{"v_avg2":"-1.93","v_max2":"9.40","v_min2":"-12.30","v_std2":"7.42","s_avg2":"-0.18","s_max2":"7.87","s_min2":"-9.18","s_std2":"5.47","alpha_avg2":"-1.75","alpha_max2":"1.53","alpha_min2":"-4.76","VCAGR":"-26.542465909469826","SCAGR":"-4.004316028237165"}]

这是我的HTML:

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src='https://code.jquery.com/jquery-3.2.1.min.js'></script>
    </head>
<body>

<h2>Testing HTML/JSON</h2>

<div>
    <span id="nums"></span>
</div>

<script>
fetch('./php/beta0472019.php')
.then(function (response){
    return response.json();
})
.then(function (json){
    console.log(json);
    var vavg = json.v_avg2;
    $('#nums').html('VIOG Mean: <span style="float:right;">' +vavg+ '</span><br>');         
});
</script>


</body>
</html>

任何帮助都会非常感谢这位初学者。

谢谢!

jquery html json undefined
1个回答
0
投票

json[0].v_avg2因为它是一个阵列

© www.soinside.com 2019 - 2024. All rights reserved.