我通过php获得这些结果以提醒我的ajax提醒

[{"message_id":"3","box":"0","from_id":"3","to_id":"1","title":"Hello sir!","message":"how are you?","sender_ip":"","date_sent":"","status":"0"}]


我该怎么办?

我只想要json数组中的指定值。

这是代码

function showMessage(id){
            var dataString = 'id=' + id;
                    $.ajax(
                    {
                        type: "POST",
                        url: "/inbox/instshow",
                        data: dataString,
                        success: function(results)
                        {

                            if(results == "error")
                            {
                                alert('An error occurred, please try again later. Email us with the issue if it persists.');
                            }

                            if(results != "notallowed" && results != "error" && results != "login")
                            {

                                alert(results);
                                alert(results[0].message);

                            }
                        }
                    });

        }

最佳答案

data = [{"message_id":"3","box":"0","from_id":"3","to_id":"1","title":"Hello sir!","message":"how are you?","sender_ip":"","date_sent":"","status":"0"}]


$('#divid').html(data[0].message);


DEMO

您可能必须使用jQuery.parseJSON解析JSON字符串。

// results is your JSON string from the request
data = jQuery.parseJSON(results);
$('#divid').html(data[0].message);

09-16 01:29