Question

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.

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.

Was it helpful?

Solution

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>"
  }
]

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top