Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I do not understand what went wrong when parsing file:

{ "t": -9.30, "p": 728.11, "h": 87.10 }

javascript code:

<script type="text/javascript">
function check() {
    $.get("http://....file.json", function(response, status, xhr) {
        if (status == "success") {
            var json = JSON.parse(response);
            $("#temp").html(json.t + "&deg;");
            $("#pressure").html(json.p + " mm hg");
        }
        if (status == "error") {
            $("#temp").html("error");
        }
    });
}

I receive error:

SyntaxError: JSON Parse error: Unexpected identifier "object"
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
798 views
Welcome To Ask or Share your Answers For Others

1 Answer

Most probably your response is already a JavaScript object and it not required to be parsed.

Remove the line var json = JSON.parse(response); and your code should work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...