0

I run json_encode PHP function and get following output:

[{"id":"1","size":"124","name":"Team1","picture":1},
{"id":"5","size":"76","name":"Team 4","picture":2},
{"id":"3","size":"25","name":"Team2","picture":3},
{"id":"4","size":"17","name":"Team3","picture":4}]

Now I want to parse it using JQUERY and add it to my web page. I run following script:

<script>
    $(function() {
      $('#myButton2').click(function(e) {
        $.get("http://localhost:99/result/getBestOne", function(data) {
        alert(data+"");
        var obj = JSON.parse(data);
        alert(obj+"");

       });
    });
});

</script>

My problem is that first alert is working, but in second one, I get error:**Ucought SyntaxError: Unexpected Token**

Where is the problem?

4

3 回答 3

5

问题是它不是有效的 JSON。最后 2 个对象的起始大括号丢失了。

{"id":"1","size":"124","name":"Team1","picture":1},
{"id":"5","size":"76","name":"Team 4","picture":2},
{"id":"3","size":"25","name":"Team2","picture":3},
{"id":"4","size":"17","name":"Team3","picture":4}
于 2013-02-24T19:18:18.413 回答
1

这两行的大括号“{”在哪里?

"id":"3","size":"25","name":"Team2","图片":3},

"id":"4","size":"17","name":"Team3","图片":4}

于 2013-02-24T19:18:59.920 回答
0

您尝试解析的文本不是有效的 JSON,因此您会收到语法错误。

如果您不确定出了什么问题,我建议您将 JSON 代码复制并粘贴到此网站中:

http://jsonlint.com/

于 2013-02-24T20:44:21.337 回答