开发者

json error: parsererror

I am developing a balloon notification for my social network. I came across this error when there's 2 or more notifications. I checked my JSON response on jsonlint.com, and I got error at line 6.

开发者_StackOverflow

JSON response:

    {
    "nid": "1101",
    "img": "<img src=\".\/images\/icons\/he_wall_post_icon.png\">",
    "notifier": "Sarah O&#039;conner",
    "url": " has commened on your <a href=\"wall_action.php?id=1463\">post<\/a>"
}{
    "nid": "1100",
    "img": "<img src=\".\/images\/icons\/he_wall_post_icon.png\">",
    "notifier": "Sarah O&#039;conner",
    "url": " likes your <a href=\"wall_action.php?id=1463\">post<\/a>"
}

here's my PHP part:

$ret_arr = array('nid' => $nid2,'img' => $img, 'notifier' => $notifier, 'url' => $url);

echo json_encode($ret_arr);

here's my JS part:

    function noob()
{
    jQuery.ajax({
        url: 'notifications.php?n=1',
        dataType: 'json',
        success: function(data){
            alert('Success!');
        },
        error: function(requeset, textStatus, errorThrown){
            alert('error:'+textStatus);
        }
    });
}

How can i get that done!

Thanks guys.


Your JSON is missing the list brackets and the comma between objects.

It should look like:

[
  {
    "nid": "1101",
    "img": "<img src=\".\/images\/icons\/he_wall_post_icon.png\">",
    "notifier": "Sarah O&#039;conner",
    "url": " has commened on your <a href=\"wall_action.php?id=1463\">post<\/a>"
  },
  {
    "nid": "1100",
    "img": "<img src=\".\/images\/icons\/he_wall_post_icon.png\">",
    "notifier": "Sarah O&#039;conner",
    "url": " likes your <a href=\"wall_action.php?id=1463\">post<\/a>"
  }
]


Copy and paste your JSON into JSONLint - it's a JSON validator that shows you what and where exactly is your problem and whether is valid or not.

Matthew is right, this is just a hint how to find it by yourself if you run into the same problem next time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜