【发布时间】:2014-02-04 18:07:42
【问题描述】:
我基本上读取了一些传感器数据,并将这些数据写入 JSON 文件。我试图在网页上显示这些读数,但我以前没有使用 jQuery 的经验。 我的measurements.json 文件包含与注释输出变量完全相同的内容。但是,当我使用注释行时,它可以工作。但是当我运行这里的代码时它不起作用;
<script type="text/javascript">
jQuery(document).ready(function(){
$("#json").load('measurements.json');
//var output = jQuery.parseJSON('{"timestamp": 1391524099.334835, "pH": 1.4132352941176471, "Temperature": -14.934640522815688, "Chlorine": 999.0},');
var output = jQuery.parseJSON("#json");
$('#celc').append(String(output.Temperature));
$('#cl').append(output.Chlorine);
$('#ph').append(output.pH);
});
</script>
<div id="json"><strong>JSON</strong>: </div>
<div id="celc"><strong>Temperatuur</strong>: </div>
<div id="cl"><strong>Chloor</strong>: </div>
<div id="ph"><strong>Zuur</strong>: </div>
我可能做了一些明显错误的事情,但我似乎无法仅使用 Google 来解决。
谢谢!
【问题讨论】:
-
什么是,在最后一个被注释的 json 中
-
您可能正在尝试在实际加载数据之前解析 json。
标签: javascript jquery json parsing