Question

Je développe une notification de ballon pour mon réseau social.Je suis tombé sur cette erreur quand il y a 2 notifications ou plus.J'ai vérifié ma réponse JSON sur JSONLINT.com , et j'ai eu une erreur à la ligne 6.

Réponse JSON:

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

Voici ma partie PHP:

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

echo json_encode($ret_arr);

Voici ma partie JS:

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

Comment puis-je l'obtenir!

Merci gars.

Était-ce utile?

La solution

Votre JSON manque les supports de la liste et la virgule entre objets.

On dirait que:

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

Autres conseils

copier et coller votre JSON en JONLINT - C'est un validateur JSON qui vous montre quoi et où est votre problème.et si elle est valide ou non.

Matthew a raison, c'est juste une allusion à la recherche de vous-même si vous rencontrez le même problème la prochaine fois.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top