Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.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 jQuery JSON解析意外字符_Javascript_Jquery_Json_Parsing - Fatal编程技术网

Javascript jQuery JSON解析意外字符

Javascript jQuery JSON解析意外字符,javascript,jquery,json,parsing,Javascript,Jquery,Json,Parsing,我基本上读取了一些传感器数据,这些数据被写入一个JSON文件。我试图在网页上展示这些阅读资料,但我以前没有使用jQuery的经验。 我的measurements.json文件包含与注释输出变量完全相同的内容。但是,当我使用注释行时,它可以工作。但当我像这里这样运行代码时,它不起作用 <script type="text/javascript"> jQuery(document).ready(function(){ $("#json").load('measurements.

我基本上读取了一些传感器数据,这些数据被写入一个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>

jQuery(文档).ready(函数(){
$(“#json”).load('measurements.json');
//var output=jQuery.parseJSON(“{”时间戳“:1391524099.334835,“pH“:1.4132352941176471,“温度“:-14.934640522815688,“氯“:999.0}”);
var output=jQuery.parseJSON(“#json”);
$('#celc').append(字符串(output.Temperature));
$('#cl').append(output.chloride);
$('#ph').append(output.ph);
});
JSON温度ChloorZuur
我可能做了一些明显的错误,但我似乎无法用谷歌来解决它

谢谢

您应该使用

异步调用。因此,当您调用
jQuery.parseJSON(“#json”)它包含
JSON
这是无效的JSON,因此您会得到异常情况,您应该使用它


异步调用。因此,当您调用
jQuery.parseJSON(“#json”)它包含
JSON
这是无效的JSON,因此您会得到异常

在最后一个JSON中,您可能在实际加载数据之前尝试解析JSON。什么是,在json的最后一部分,即Comentedy中,您可能试图在实际加载数据之前解析json。感谢您的有用评论。我再也不会出错了!我不明白的是我的现在没有得到追加。或者可能是,但它只是一个空文本。是否有办法检查或解决此问题?谢谢您的宝贵意见。我再也不会出错了!我不明白的是我的现在没有得到追加。或者可能是,但它只是一个空文本。有没有办法检查或解决这个问题?
$.getJSON( 'measurements.json' function(data){
    $('#celc').append(String(data.Temperature));
    $('#cl').append(data.Chlorine);
    $('#ph').append(data.pH);
}).error(function() { alert("error"); });