views:

34

answers:

2

Hello Guys, am developing a balloon notifications for my social network. i came across this error when there's 2 or more notifications. i checked my json response on jsonlint.com 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.

+1  A: 

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>"
  }
]
Matthew Schinckel
thanks Matthew that would work
clonex1
+1  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.

Igor Pavelek